Conditions | 2 |
Paths | 2 |
Total Lines | 22 |
Code Lines | 12 |
Lines | 0 |
Ratio | 0 % |
Tests | 13 |
CRAP Score | 2 |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
28 | public function getInstance(string $name, $value = null): AttributeInterface |
||
29 | { |
||
30 | 32 | $attribute_classname = static::$registry[$name] ?? static::$registry['*']; |
|
31 | |||
32 | 32 | if (!in_array(AttributeInterface::class, class_implements($attribute_classname), true)) { |
|
33 | 1 | throw new Exception( |
|
34 | 32 | sprintf( |
|
35 | 'The class (%s) must implement the interface %s.', |
||
36 | 32 | $attribute_classname, |
|
37 | 1 | AttributeInterface::class |
|
38 | 1 | ) |
|
39 | 1 | ); |
|
40 | 1 | } |
|
41 | 1 | ||
42 | /** @var \drupol\htmltag\Attribute\AttributeInterface $attribute */ |
||
43 | $attribute = (new ReflectionClass($attribute_classname)) |
||
44 | ->newInstanceArgs([ |
||
45 | $name, |
||
46 | $value, |
||
47 | 31 | ]); |
|
48 | 31 | ||
49 | 31 | return $attribute; |
|
50 | 31 | } |
|
52 |