AttributesFactory::getInstance()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 18
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 8
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 18
ccs 6
cts 6
cp 1
crap 1
rs 10
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