Total Complexity | 6 |
Total Lines | 48 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
13 | #[Attribute(Attribute::TARGET_CLASS | Attribute::TARGET_CLASS_CONSTANT | Attribute::IS_REPEATABLE)] |
||
14 | class Meta |
||
15 | { |
||
16 | /** |
||
17 | * The declared meta and related values. |
||
18 | * |
||
19 | * @var array<string, mixed> |
||
20 | */ |
||
21 | protected array $all; |
||
22 | |||
23 | /** |
||
24 | * Instantiate the class. |
||
25 | */ |
||
26 | 49 | public function __construct(mixed ...$meta) |
|
27 | { |
||
28 | 49 | foreach ($meta as $key => $value) { |
|
29 | 49 | if (! is_string($key)) { |
|
30 | 1 | throw new InvalidArgumentException('The name of meta must be a string'); |
|
31 | } |
||
32 | |||
33 | 48 | $this->all[$key] = $value; |
|
34 | } |
||
35 | } |
||
36 | |||
37 | /** |
||
38 | * Retrieve the meta names. |
||
39 | * |
||
40 | * @return string[] |
||
41 | */ |
||
42 | 8 | public function names(): array |
|
45 | } |
||
46 | |||
47 | /** |
||
48 | * Determine whether the given meta exists. |
||
49 | */ |
||
50 | 44 | public function has(string $meta): bool |
|
51 | { |
||
52 | 44 | return array_key_exists($meta, $this->all); |
|
53 | } |
||
54 | |||
55 | /** |
||
56 | * Retrieve the value for the given meta. |
||
57 | */ |
||
58 | 40 | public function get(string $meta): mixed |
|
61 | } |
||
62 | } |
||
63 |