Conditions | 2 |
Paths | 2 |
Total Lines | 31 |
Code Lines | 15 |
Lines | 0 |
Ratio | 0 % |
Tests | 15 |
CRAP Score | 2 |
Changes | 4 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
35 | public function getInstance( |
||
36 | string $name, |
||
37 | array $attributes = [], |
||
38 | 5 | $content = null |
|
39 | ): TagInterface { |
||
40 | $attributes_factory_classname = static::$registry['attributes_factory']; |
||
41 | |||
42 | /** @var AttributesInterface $attributes */ |
||
43 | 5 | $attributes = $attributes_factory_classname::build($attributes); |
|
44 | |||
45 | $tag_classname = static::$registry[$name] ?? static::$registry['*']; |
||
46 | 5 | ||
47 | if (!in_array(TagInterface::class, class_implements($tag_classname), true)) { |
||
48 | 5 | throw new Exception( |
|
49 | 3 | sprintf( |
|
50 | 5 | 'The class (%s) must implement the interface %s.', |
|
51 | $tag_classname, |
||
52 | 5 | TagInterface::class |
|
53 | 1 | ) |
|
54 | 1 | ); |
|
55 | 1 | } |
|
56 | 1 | ||
57 | 1 | /** @var \drupol\htmltag\Tag\TagInterface $tag */ |
|
58 | $tag = (new ReflectionClass($tag_classname)) |
||
59 | ->newInstanceArgs([ |
||
60 | $attributes, |
||
61 | $name, |
||
62 | $content, |
||
63 | 4 | ]); |
|
64 | 4 | ||
65 | 4 | return $tag; |
|
66 | 4 | } |
|
68 |