1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Caxy\HtmlDiff\Table; |
4
|
|
|
|
5
|
|
|
class DiffRowPosition |
6
|
|
|
{ |
7
|
|
|
protected $indexInOld; |
8
|
|
|
|
9
|
|
|
protected $indexInNew; |
10
|
|
|
|
11
|
|
|
protected $columnInOld; |
12
|
|
|
|
13
|
|
|
protected $columnInNew; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* DiffRowPosition constructor. |
17
|
|
|
* @param $indexInOld |
18
|
|
|
* @param $indexInNew |
19
|
|
|
* @param $columnInOld |
20
|
|
|
* @param $columnInNew |
21
|
|
|
*/ |
22
|
|
|
public function __construct($indexInOld = 0, $indexInNew = 0, $columnInOld = 0, $columnInNew = 0) |
23
|
|
|
{ |
24
|
|
|
$this->indexInOld = $indexInOld; |
25
|
|
|
$this->indexInNew = $indexInNew; |
26
|
|
|
$this->columnInOld = $columnInOld; |
27
|
|
|
$this->columnInNew = $columnInNew; |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @return int |
32
|
|
|
*/ |
33
|
|
|
public function getIndexInOld() |
34
|
|
|
{ |
35
|
|
|
return $this->indexInOld; |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @param int $indexInOld |
40
|
|
|
* @return DiffRowPosition |
41
|
|
|
*/ |
42
|
|
|
public function setIndexInOld($indexInOld) |
43
|
|
|
{ |
44
|
|
|
$this->indexInOld = $indexInOld; |
45
|
|
|
return $this; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @return int |
50
|
|
|
*/ |
51
|
|
|
public function getIndexInNew() |
52
|
|
|
{ |
53
|
|
|
return $this->indexInNew; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @param int $indexInNew |
58
|
|
|
* @return DiffRowPosition |
59
|
|
|
*/ |
60
|
|
|
public function setIndexInNew($indexInNew) |
61
|
|
|
{ |
62
|
|
|
$this->indexInNew = $indexInNew; |
63
|
|
|
return $this; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @return int |
68
|
|
|
*/ |
69
|
|
|
public function getColumnInOld() |
70
|
|
|
{ |
71
|
|
|
return $this->columnInOld; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* @param int $columnInOld |
76
|
|
|
* @return DiffRowPosition |
77
|
|
|
*/ |
78
|
|
|
public function setColumnInOld($columnInOld) |
79
|
|
|
{ |
80
|
|
|
$this->columnInOld = $columnInOld; |
81
|
|
|
return $this; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* @return int |
86
|
|
|
*/ |
87
|
|
|
public function getColumnInNew() |
88
|
|
|
{ |
89
|
|
|
return $this->columnInNew; |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* @param int $columnInNew |
94
|
|
|
* @return DiffRowPosition |
95
|
|
|
*/ |
96
|
|
|
public function setColumnInNew($columnInNew) |
97
|
|
|
{ |
98
|
|
|
$this->columnInNew = $columnInNew; |
99
|
|
|
return $this; |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
public function incrementColumnInNew($increment = 1) |
103
|
|
|
{ |
104
|
|
|
$this->columnInNew += $increment; |
105
|
|
|
|
106
|
|
|
return $this->columnInNew; |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
public function incrementColumnInOld($increment = 1) |
110
|
|
|
{ |
111
|
|
|
$this->columnInOld += $increment; |
112
|
|
|
|
113
|
|
|
return $this->columnInOld; |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
public function incrementIndexInNew($increment = 1) |
117
|
|
|
{ |
118
|
|
|
$this->indexInNew += $increment; |
119
|
|
|
|
120
|
|
|
return $this->indexInNew; |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
public function incrementIndexInOld($increment = 1) |
124
|
|
|
{ |
125
|
|
|
$this->indexInOld += $increment; |
126
|
|
|
|
127
|
|
|
return $this->indexInOld; |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
public function incrementIndex($type, $increment = 1) |
131
|
|
|
{ |
132
|
|
|
if ($type === 'new') { |
133
|
|
|
return $this->incrementIndexInNew($increment); |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
return $this->incrementIndexInOld($increment); |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
public function incrementColumn($type, $increment = 1) |
140
|
|
|
{ |
141
|
|
|
if ($type === 'new') { |
142
|
|
|
return $this->incrementColumnInNew($increment); |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
return $this->incrementColumnInOld($increment); |
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
public function isColumnLessThanOther($type) |
149
|
|
|
{ |
150
|
|
|
if ($type === 'new') { |
151
|
|
|
return $this->getColumnInNew() < $this->getColumnInOld(); |
152
|
|
|
} |
153
|
|
|
|
154
|
|
|
return $this->getColumnInOld() < $this->getColumnInNew(); |
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
public function getColumn($type) |
158
|
|
|
{ |
159
|
|
|
if ($type === 'new') { |
160
|
|
|
return $this->getColumnInNew(); |
161
|
|
|
} |
162
|
|
|
|
163
|
|
|
return $this->getColumnInOld(); |
164
|
|
|
} |
165
|
|
|
|
166
|
|
|
public function getIndex($type) |
167
|
|
|
{ |
168
|
|
|
if ($type === 'new') { |
169
|
|
|
return $this->getIndexInNew(); |
170
|
|
|
} |
171
|
|
|
|
172
|
|
|
return $this->getIndexInOld(); |
173
|
|
|
} |
174
|
|
|
|
175
|
|
|
public function areColumnsEqual() |
176
|
|
|
{ |
177
|
|
|
return $this->getColumnInOld() === $this->getColumnInNew(); |
178
|
|
|
} |
179
|
|
|
|
180
|
|
|
public function getLesserColumnType() |
181
|
|
|
{ |
182
|
|
|
if ($this->isColumnLessThanOther('new')) { |
183
|
|
|
return 'new'; |
184
|
|
|
} elseif ($this->isColumnLessThanOther('old')) { |
185
|
|
|
return 'old'; |
186
|
|
|
} |
187
|
|
|
|
188
|
|
|
return null; |
189
|
|
|
} |
190
|
|
|
} |