Completed
Push — master ( d4e957...308746 )
by Pol
02:55
created

HtmlTag::comment()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 17

Duplication

Lines 17
Ratio 100 %

Code Coverage

Tests 8
CRAP Score 2

Importance

Changes 0
Metric Value
dl 17
loc 17
ccs 8
cts 8
cp 1
rs 9.7
c 0
b 0
f 0
cc 2
nc 2
nop 2
crap 2
1
<?php
2
3
namespace drupol\htmltag;
4
5
use drupol\htmltag\Attribute\AttributeFactory;
6
use drupol\htmltag\Attributes\AttributesFactory;
7
use drupol\htmltag\Tag\CommentFactory;
8
use drupol\htmltag\Tag\TagFactory;
9
10
/**
11
 * Class HtmlTag
12
 */
13
class HtmlTag implements HtmlTagInterface
14
{
15
    /**
16
     * The attribute factory classname.
17
     *
18
     * @var string
19
     */
20
    protected $attribute_factory_classname = AttributeFactory::class;
21
22
    /**
23
     * The attributes factory classname.
24
     *
25
     * @var string
26
     */
27
    protected $attributes_factory_classname = AttributesFactory::class;
28
29
    /**
30
     * The tag factory classname.
31
     *
32
     * @var string
33
     */
34
    protected $tag_factory_classname = TagFactory::class;
35
36
    /**
37
     * The comment factory classname.
38
     *
39
     * @var string
40
     */
41
    protected $comment_factory_classname = CommentFactory::class;
42
43
    /**
44
     * {@inheritdoc}
45
     */
46 1
    public static function tag(
47
        $name,
48
        array $attributes = [],
49
        $content = null,
50
        $attribute_factory_classname = null,
51
        $attributes_factory_classname = null,
52
        $tag_factory_classname = null
53
    ) {
54 1
        $static = new static();
55
56 1
        $attributes_factory_classname = null == $attributes_factory_classname ?
0 ignored issues
show
Bug introduced by
It seems like you are loosely comparing $attributes_factory_classname of type string|null against null; this is ambiguous if the string can be empty. Consider using a strict comparison === instead.
Loading history...
57 1
            $static->attributes_factory_classname :
58 1
            $attributes_factory_classname;
59
60 1
        $attribute_factory_classname = null == $attribute_factory_classname ?
0 ignored issues
show
Bug introduced by
It seems like you are loosely comparing $attribute_factory_classname of type string|null against null; this is ambiguous if the string can be empty. Consider using a strict comparison === instead.
Loading history...
61 1
            $static->attribute_factory_classname :
62 1
            $attribute_factory_classname;
63
64 1
        $tag_factory_classname = null == $tag_factory_classname ?
0 ignored issues
show
Bug introduced by
It seems like you are loosely comparing $tag_factory_classname of type string|null against null; this is ambiguous if the string can be empty. Consider using a strict comparison === instead.
Loading history...
65 1
            $static->tag_factory_classname :
66 1
            $tag_factory_classname;
67
        /** @var \drupol\htmltag\Tag\TagFactoryInterface $tag_factory_classname */
68 1
        $tag_factory_classname = (new \ReflectionClass($tag_factory_classname))->newInstance();
69
70 1
        return $tag_factory_classname::build(
71 1
            $name,
72 1
            $attributes,
73 1
            $content,
74 1
            $attribute_factory_classname,
75 1
            $attributes_factory_classname
76
        );
77
    }
78
79
    /**
80
     * {@inheritdoc}
81
     */
82 1 View Code Duplication
    public static function comment(
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...
83
        $content = null,
84
        $comment_factory_classname = null
85
    ) {
86 1
        $static = new static();
87
88 1
        $comment_factory_classname = null == $comment_factory_classname ?
89 1
            $static->comment_factory_classname :
90 1
            $comment_factory_classname;
91
92
        /** @var \drupol\htmltag\Tag\CommentFactory $comment_factory_classname */
93 1
        $comment_factory_classname = (new \ReflectionClass($comment_factory_classname))->newInstance();
94
95 1
        return $comment_factory_classname::build(
96 1
            $content
97
        );
98
    }
99
100
    /**
101
     * {@inheritdoc}
102
     */
103 1
    public static function attributes(
104
        array $attributes = [],
105
        $attribute_factory_classname = null,
106
        $attributes_factory_classname = null
107
    ) {
108 1
        $static = new static();
109
110 1
        $attribute_factory_classname = null == $attribute_factory_classname ?
0 ignored issues
show
Bug introduced by
It seems like you are loosely comparing $attribute_factory_classname of type string|null against null; this is ambiguous if the string can be empty. Consider using a strict comparison === instead.
Loading history...
111 1
            $static->attribute_factory_classname :
112 1
            $attribute_factory_classname;
113
114 1
        $attributes_factory_classname = null == $attributes_factory_classname ?
0 ignored issues
show
Bug introduced by
It seems like you are loosely comparing $attributes_factory_classname of type string|null against null; this is ambiguous if the string can be empty. Consider using a strict comparison === instead.
Loading history...
115 1
            $static->attributes_factory_classname :
116 1
            $attributes_factory_classname;
117
118
        /** @var \drupol\htmltag\Attributes\AttributesFactoryInterface $attributes_factory_classname */
119 1
        $attributes_factory_classname = (new \ReflectionClass($attributes_factory_classname))->newInstance();
120
121 1
        return $attributes_factory_classname::build(
122 1
            $attributes,
123 1
            $attribute_factory_classname
124
        );
125
    }
126
127
    /**
128
     * {@inheritdoc}
129
     */
130 1 View Code Duplication
    public static function attribute(
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...
131
        $name,
132
        $value,
133
        $attribute_factory_classname = null
134
    ) {
135 1
        $static = new static();
136
137 1
        $attribute_factory_classname = null == $attribute_factory_classname ?
0 ignored issues
show
Bug introduced by
It seems like you are loosely comparing $attribute_factory_classname of type string|null against null; this is ambiguous if the string can be empty. Consider using a strict comparison === instead.
Loading history...
138 1
            $static->attribute_factory_classname :
139 1
            $attribute_factory_classname;
140
141
        /** @var \drupol\htmltag\Attribute\AttributeFactoryInterface $attribute_factory_classname */
142 1
        $attribute_factory_classname = (new \ReflectionClass($attribute_factory_classname))->newInstance();
143
144 1
        return $attribute_factory_classname::build($name, $value);
145
    }
146
}
147