AttributesFactory   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 13
c 1
b 0
f 0
dl 0
loc 36
ccs 7
cts 7
cp 1
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getInstance() 0 18 1
A build() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace drupol\htmltag\Attributes;
6
7
use drupol\htmltag\Attribute\AttributeFactory;
8
use ReflectionClass;
9
10
class AttributesFactory implements AttributesFactoryInterface
11
{
12
    /**
13
     * The classes registry.
14
     *
15
     * @var array
16
     */
17
    public static $registry = [
18
        'attribute_factory' => AttributeFactory::class,
19
        '*' => Attributes::class,
20
    ];
21
22
    public static function build(
23
        array $attributes = []
24
    ) {
25 16
        return (new static())->getInstance($attributes);
26
    }
27
28 16
    public function getInstance(
29
        array $attributes = []
30
    ) {
31
        $attribute_factory_classname = static::$registry['attribute_factory'];
32
33
        /** @var \drupol\htmltag\Attribute\AttributeFactoryInterface $attribute_factory_classname */
34 16
        $attribute_factory_classname = (new ReflectionClass($attribute_factory_classname))->newInstance();
35
36
        $attributes_classname = static::$registry['*'];
37 16
38
        /** @var \drupol\htmltag\Attributes\AttributesInterface $attributes */
39
        $attributes = (new ReflectionClass($attributes_classname))
40 16
            ->newInstanceArgs([
41
                $attribute_factory_classname,
42 16
                $attributes,
43
            ]);
44
45 16
        return $attributes;
46 16
    }
47
}
48