Completed
Push — master ( 97bc30...8f50f7 )
by Pol
09:42 queued 06:23
created

HtmlTag::attributes()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 13

Duplication

Lines 13
Ratio 100 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 13
loc 13
ccs 0
cts 11
cp 0
rs 9.8333
c 0
b 0
f 0
cc 2
nc 2
nop 2
crap 6
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\AttributesInterface;
10
use drupol\htmltag\Attributes\AttributesFactory;
11
use drupol\htmltag\Attributes\AttributesFactoryInterface;
12
use drupol\htmltag\Tag\Tag;
13
14
/**
15
 * Class HtmlTag
16
 */
17
final class HtmlTag implements HtmlTagInterface
18
{
19
    /**
20
     * {@inheritdoc}
21
     */
22 View Code Duplication
    public static function tag(
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...
23
        $name,
24
        array $attributes = [],
25
        $content = false,
26
        AttributesFactoryInterface $attributesFactory = null,
27
        AttributeFactoryInterface $attributeFactory = null
28
    ) {
29
        /** @var AttributeFactoryInterface $attributeFactory */
30
        $attributeFactory = null === $attributeFactory?
31
            (new \ReflectionClass(AttributeFactory::class))->newInstance():
32
            $attributeFactory;
33
34
        /** @var AttributesFactoryInterface $attributesFactory */
35
        $attributesFactory = null === $attributesFactory ?
36
            (new \ReflectionClass(AttributesFactory::class))->newInstance():
37
            $attributesFactory;
38
39
        /** @var AttributesInterface $attributes */
40
        $attributes = ($attributesFactory)::build($attributes, $attributeFactory);
41
42
        return new Tag($attributes, $name, $content);
43
    }
44
45
    /**
46
     * {@inheritdoc}
47
     */
48 View Code Duplication
    public function attributes(array $attributes = [], 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...
49
    {
50
        if (null === $attributeFactory) {
51
            /** @var \drupol\htmltag\Attribute\AttributeFactoryInterface $attributeFactory */
52
            $attributeFactory = (new \ReflectionClass(AttributeFactory::class))
53
                ->newInstance();
54
        }
55
56
        return new Attributes(
57
            $attributeFactory,
58
            $attributes
59
        );
60
    }
61
62
    /**
63
     * {@inheritdoc}
64
     */
65
    public static function attr($name, ...$value)
66
    {
67
        return new Attribute($name, $value);
68
    }
69
}
70