Completed
Push — master ( 24da9e...18bd75 )
by Josh
05:16
created

DiffListItem::setText()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
c 1
b 1
f 0
dl 0
loc 6
rs 9.4286
cc 1
eloc 3
nc 1
nop 1
1
<?php
2
3
namespace Caxy\HtmlDiff\ListDiff;
4
5
class DiffListItem
6
{
7
    protected $attributes = array();
8
9
    protected $text;
10
11
    protected $startTag;
12
13
    protected $endTag;
14
15
    public function __construct($text, $attributes = array(), $startTag, $endTag)
0 ignored issues
show
Coding Style introduced by
Parameters which have default values should be placed at the end.

If you place a parameter with a default value before a parameter with a default value, the default value of the first parameter will never be used as it will always need to be passed anyway:

// $a must always be passed; it's default value is never used.
function someFunction($a = 5, $b) { }
Loading history...
16
    {
17
        $this->text = $text;
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 7 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
18
        $this->attributes = $attributes;
19
        $this->startTag = $startTag;
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 3 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
20
        $this->endTag = $endTag;
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 5 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
21
    }
22
23
    /**
24
     * @return array
25
     */
26
    public function getAttributes()
27
    {
28
        return $this->attributes;
29
    }
30
31
    /**
32
     * @param array $attributes
33
     *
34
     * @return DiffListItem
35
     */
36
    public function setAttributes($attributes)
37
    {
38
        $this->attributes = $attributes;
39
40
        return $this;
41
    }
42
43
    /**
44
     * @return mixed
45
     */
46
    public function getText()
47
    {
48
        return $this->text;
49
    }
50
51
    /**
52
     * @param mixed $text
53
     *
54
     * @return DiffListItem
55
     */
56
    public function setText($text)
57
    {
58
        $this->text = $text;
59
60
        return $this;
61
    }
62
63
    /**
64
     * @return mixed
65
     */
66
    public function getStartTag()
67
    {
68
        return $this->startTag;
69
    }
70
71
    public function getStartTagWithDiffClass($class = 'normal')
72
    {
73
        return str_replace('>', ' class="'.$class.'">', $this->startTag);
74
    }
75
76
    /**
77
     * @param mixed $startTag
78
     *
79
     * @return DiffListItem
80
     */
81
    public function setStartTag($startTag)
82
    {
83
        $this->startTag = $startTag;
84
85
        return $this;
86
    }
87
88
    /**
89
     * @return mixed
90
     */
91
    public function getEndTag()
92
    {
93
        return $this->endTag;
94
    }
95
96
    /**
97
     * @param mixed $endTag
98
     *
99
     * @return DiffListItem
100
     */
101
    public function setEndTag($endTag)
102
    {
103
        $this->endTag = $endTag;
104
105
        return $this;
106
    }
107
108
    public function getHtml($class = 'normal', $wrapTag = null)
109
    {
110
        $startWrap = $wrapTag ? sprintf('<%s>', $wrapTag) : '';
111
        $endWrap = $wrapTag ? sprintf('</%s>', $wrapTag) : '';
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 3 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
112
        return sprintf('%s%s%s%s%s', $this->getStartTagWithDiffClass($class), $startWrap, $this->getInnerHtml(), $endWrap, $this->endTag);
113
    }
114
115
    public function getInnerHtml()
116
    {
117
        return implode('', $this->text);
118
    }
119
120
    public function __toString()
121
    {
122
        return $this->getHtml();
123
    }
124
}