Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
1 / 1
CRAP
100.00% covered (success)
100.00%
1 / 1
Tools
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
1 / 1
5
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
1 / 1
5
1<?php
2
3declare(strict_types=1);
4
5namespace Cosray\Schema;
6
7use Attribute;
8use Cosray\Exception\RuntimeException;
9
10/**
11 * Arguments may mix single cases with lists, because attribute argument
12 * lists forbid unpacking a preset: `#[Tools(Tool::DEFAULT, Tool::Align)]`.
13 */
14#[Attribute(Attribute::TARGET_PROPERTY)]
15readonly class Tools
16{
17    /** @var list<Tool> */
18    public array $tools;
19
20    /** @param Tool|array<mixed> ...$tools */
21    public function __construct(Tool|array ...$tools)
22    {
23        $flat = [];
24
25        foreach ($tools as $entry) {
26            foreach (is_array($entry) ? $entry : [$entry] as $tool) {
27                if (!$tool instanceof Tool) {
28                    throw new RuntimeException('#[Tools] lists may only contain Tool cases');
29                }
30
31                $flat[] = $tool;
32            }
33        }
34
35        $this->tools = $flat;
36    }
37}