Completed
Push — master ( d17a12...aafb0b )
by Pol
39:01
created

HtmlTag::tag()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 17

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
dl 0
loc 17
ccs 0
cts 13
cp 0
rs 9.7
c 0
b 0
f 0
cc 3
nc 4
nop 3
crap 12
1
<?php
2
3
namespace drupol\htmltag;
4
5
use drupol\htmltag\Attribute\Attribute;
6
use drupol\htmltag\Attribute\AttributeFactory;
7
use drupol\htmltag\Attribute\AttributeFactoryInterface;
8
use drupol\htmltag\Attributes\Attributes;
9
use drupol\htmltag\Attributes\AttributesFactory;
10
use drupol\htmltag\Attributes\AttributesFactoryInterface;
11
use drupol\htmltag\Tag\Tag;
12
13
/**
14
 * Class HtmlTag
15
 */
16
final class HtmlTag implements HtmlTagInterface
17
{
18
    /**
19
     * {@inheritdoc}
20
     */
21
    public static function tag(
22
        $name,
23
        AttributesFactoryInterface $attributesFactory = null,
24
        AttributeFactoryInterface $attributeFactory = null
25
    ) {
26
        /** @var AttributeFactoryInterface $attributeFactory */
27
        $attributeFactory = $attributeFactory === null ?
28
            (new \ReflectionClass(AttributeFactory::class))->newInstance():
29
            $attributesFactory;
30
31
        /** @var AttributesFactoryInterface $attributesFactory */
32
        $attributesFactory = $attributesFactory === null ?
33
            (new \ReflectionClass(AttributesFactory::class))->newInstanceArgs([$attributeFactory]):
34
            $attributesFactory;
35
36
        return new Tag($attributesFactory, $name);
37
    }
38
39
    /**
40
     * {@inheritdoc}
41
     */
42 View Code Duplication
    public function attributes(array $attributes = array(), AttributeFactoryInterface $attributeFactory = null)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
43
    {
44
        if ($attributeFactory === null) {
45
            $reflection = new \ReflectionClass(AttributeFactory::class);
46
            /** @var \drupol\htmltag\Attribute\AttributeFactoryInterface $attributeFactory */
47
            $attributeFactory = $reflection->newInstance();
48
        }
49
50
        return new Attributes(
51
            $attributeFactory,
52
            $attributes
53
        );
54
    }
55
56
    /**
57
     * {@inheritdoc}
58
     */
59
    public static function attr($name, ...$value)
60
    {
61
        return new Attribute($name, $value);
62
    }
63
}
64