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 |
|
|
|
|
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 |
|
|
|
|
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 |
|
|
|
|
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
|
|
|
|
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.