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    public function __construct(Tool|array ...$tools)
21    {
22        $flat = [];
23
24        foreach ($tools as $entry) {
25            foreach (is_array($entry) ? $entry : [$entry] as $tool) {
26                if (!$tool instanceof Tool) {
27                    throw new RuntimeException('#[Tools] lists may only contain Tool cases');
28                }
29
30                $flat[] = $tool;
31            }
32        }
33
34        $this->tools = $flat;
35    }
36}