Completed
Pull Request — master (#10)
by Steve
04:31
created

ChangeTextGenerator::getHtmlLayoutChanges()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 1
cts 1
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * (c) Steve Nebes <[email protected]>
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 */
8
9
declare(strict_types=1);
10
11
namespace DaisyDiff\Html\Ancestor;
12
13
use DaisyDiff\Html\Ancestor\TagToString\TagToStringFactory;
14
use DaisyDiff\Html\ChangeText;
15
use DaisyDiff\Html\Dom\TagNode;
16
use DaisyDiff\Html\Modification\HtmlLayoutChange;
17
use DaisyDiff\RangeDifferencer\RangeDifference;
18
19
/**
20
 * ChangeTextGenerator
21
 */
22
class ChangeTextGenerator
23
{
24
    /** @var HtmlLayoutChange[] */
25
    private $htmlLayoutChanges = [];
26
27
    /** @var AncestorComparator */
28
    private $ancestorComparator;
29
30
    /** @var AncestorComparator */
31
    private $other;
32
33
    /** @var TagToStringFactory */
34
    private $factory;
35
36
    /**
37
     * @param AncestorComparator $ancestorComparator
38
     * @param AncestorComparator $other
39 7
     */
40
    public function __construct(AncestorComparator $ancestorComparator, AncestorComparator $other)
41 7
    {
42 7
        $this->ancestorComparator = $ancestorComparator;
43
        $this->other = $other;
44 7
45 7
        $this->factory = new TagToStringFactory();
46
    }
47
48
    /**
49
     * @param RangeDifference[] $differences
50
     * @return ChangeText
51 6
     */
52
    public function getChanged(array $differences): ChangeText
0 ignored issues
show
Unused Code introduced by
The parameter $differences is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

52
    public function getChanged(/** @scrutinizer ignore-unused */ array $differences): ChangeText

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
53 6
    {
54 6
        $text = new ChangeText();
55
//        $rootListOpened = false;
56 6
//
57
//        if (\count($differences) > 1) {
58
//            $text->addHtml('<ul class="changelist">');
59
//            $rootListOpened = true;
60
//        }
61 6
//
62
//        for ($j = 0, $jMax = \count($differences); $j < $jMax; $j++) {
63 6
//            /** @var RangeDifference $d */
64 6
//            $d = $differences[$j];
65
//            $lvl1ListOpened = false;
66 6
//
67
//            if ($rootListOpened) {
68
//                $text->addHtml('<li>');
69
//            }
70 6
//
71 6
//            if ($d->getLeftLength() + $d->getRightLength() > 1) {
72 6
//                $text->addHtml('<ul class="changelist">');
73
//                $lvl1ListOpened = true;
74
//            }
75
//
76 6
//            // Left are the old ones.
77 6
//            for ($i = $d->getLeftStart(), $iMax = $d->getLeftEnd(); $i < $iMax; $i++) {
78 6
//                if ($lvl1ListOpened) {
79
//                    $text->addHtml('<li>');
80
//                }
81
//
82 6
//                // Add a bullet for an old tag.
83
//                $this->addTagOld($text, $this->other->getAncestor($i));
84 6
//
85 6
//                if ($lvl1ListOpened) {
86
//                    $text->addHtml('</li>');
87
//                }
88
//            }
89
//
90 6
//            // Right are the new ones.
91 6
//            for ($i = $d->getRightStart(), $iMax = $d->getRightEnd(); $i < $iMax; $i++) {
92 6
//                if ($lvl1ListOpened) {
93
//                    $text->addHtml('<li>');
94
//                }
95
//
96 6
//                // Add a bullet for an old tag.
97
//                $this->addTagNew($text, $this->getAncestor($i));
98 6
//
99 6
//                if ($lvl1ListOpened) {
100
//                    $text->addHtml('</li>');
101
//                }
102
//            }
103 6
//
104 6
//            if ($lvl1ListOpened) {
105
//                $text->addHtml('</ul>');
106
//            }
107 6
//
108
//            if ($rootListOpened) {
109
//                $text->addHtml('</li>');
110
//            }
111
//        }
112 6
//
113
//        if ($rootListOpened) {
114
//            $text->addHtml('</ul>');
115
//        }
116 6
117
        return $text;
118
    }
119
120
    /**
121
     * @param ChangeText $text
122
     * @param TagNode    $ancestor
123 6
     */
124
    private function addTagOld(ChangeText $text, TagNode $ancestor): void
0 ignored issues
show
Unused Code introduced by
The parameter $text is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

124
    private function addTagOld(/** @scrutinizer ignore-unused */ ChangeText $text, TagNode $ancestor): void

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The method addTagOld() is not used, and could be removed.

This check looks for private methods that have been defined, but are not used inside the class.

Loading history...
Unused Code introduced by
The parameter $ancestor is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

124
    private function addTagOld(ChangeText $text, /** @scrutinizer ignore-unused */ TagNode $ancestor): void

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
125 6
    {
126 6
//        $tagToString = $this->factory->create($ancestor);
127 6
//        $tagToString->getRemovedDescription($text);
128 6
//        $this->htmlLayoutChanges[] = $tagToString->getHtmlLayoutChange();
129
    }
130
131
    /**
132
     * @param ChangeText $text
133
     * @param TagNode    $ancestor
134 6
     */
135
    private function addTagNew(ChangeText $text, TagNode $ancestor): void
0 ignored issues
show
Unused Code introduced by
The method addTagNew() is not used, and could be removed.

This check looks for private methods that have been defined, but are not used inside the class.

Loading history...
Unused Code introduced by
The parameter $ancestor is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

135
    private function addTagNew(ChangeText $text, /** @scrutinizer ignore-unused */ TagNode $ancestor): void

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $text is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

135
    private function addTagNew(/** @scrutinizer ignore-unused */ ChangeText $text, TagNode $ancestor): void

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
136 6
    {
137 6
//        $tagToString = $this->factory->create($ancestor);
138 6
//        $tagToString->getAddedDescription($text);
139 6
//        $this->htmlLayoutChanges[] = $tagToString->getHtmlLayoutChange();
140
    }
141
142
    /**
143
     * @param int $index
144
     * @return TagNode
145 6
     */
146
    private function getAncestor(int $index): TagNode
147 6
    {
148
        return $this->ancestorComparator->getAncestor($index);
149
    }
150
151
    /**
152
     * @return HtmlLayoutChange[]
153 6
     */
154
    public function getHtmlLayoutChanges(): array
155 6
    {
156
        return $this->htmlLayoutChanges;
157
    }
158
}
159