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

HtmlTag   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 48
Duplicated Lines 27.08 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 6
lcom 0
cbo 3
dl 13
loc 48
ccs 0
cts 28
cp 0
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A tag() 0 17 3
A attributes() 13 13 2
A attr() 0 4 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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