3e05841cf1c941acb2934cfb4c0f63c2bbca5d24
[yaffs-website] / vendor / caxy / php-htmldiff / lib / Caxy / HtmlDiff / Table / DiffRowPosition.php
1 <?php
2
3 namespace Caxy\HtmlDiff\Table;
4
5 /**
6  * Class DiffRowPosition.
7  */
8 class DiffRowPosition
9 {
10     /**
11      * @var int
12      */
13     protected $indexInOld;
14
15     /**
16      * @var int
17      */
18     protected $indexInNew;
19
20     /**
21      * @var int
22      */
23     protected $columnInOld;
24
25     /**
26      * @var int
27      */
28     protected $columnInNew;
29
30     /**
31      * DiffRowPosition constructor.
32      *
33      * @param int $indexInOld
34      * @param int $indexInNew
35      * @param int $columnInOld
36      * @param int $columnInNew
37      */
38     public function __construct($indexInOld = 0, $indexInNew = 0, $columnInOld = 0, $columnInNew = 0)
39     {
40         $this->indexInOld = $indexInOld;
41         $this->indexInNew = $indexInNew;
42         $this->columnInOld = $columnInOld;
43         $this->columnInNew = $columnInNew;
44     }
45
46     /**
47      * @return int
48      */
49     public function getIndexInOld()
50     {
51         return $this->indexInOld;
52     }
53
54     /**
55      * @param int $indexInOld
56      *
57      * @return DiffRowPosition
58      */
59     public function setIndexInOld($indexInOld)
60     {
61         $this->indexInOld = $indexInOld;
62
63         return $this;
64     }
65
66     /**
67      * @return int
68      */
69     public function getIndexInNew()
70     {
71         return $this->indexInNew;
72     }
73
74     /**
75      * @param int $indexInNew
76      *
77      * @return DiffRowPosition
78      */
79     public function setIndexInNew($indexInNew)
80     {
81         $this->indexInNew = $indexInNew;
82
83         return $this;
84     }
85
86     /**
87      * @return int
88      */
89     public function getColumnInOld()
90     {
91         return $this->columnInOld;
92     }
93
94     /**
95      * @param int $columnInOld
96      *
97      * @return DiffRowPosition
98      */
99     public function setColumnInOld($columnInOld)
100     {
101         $this->columnInOld = $columnInOld;
102
103         return $this;
104     }
105
106     /**
107      * @return int
108      */
109     public function getColumnInNew()
110     {
111         return $this->columnInNew;
112     }
113
114     /**
115      * @param int $columnInNew
116      *
117      * @return DiffRowPosition
118      */
119     public function setColumnInNew($columnInNew)
120     {
121         $this->columnInNew = $columnInNew;
122
123         return $this;
124     }
125
126     /**
127      * @param int $increment
128      *
129      * @return int
130      */
131     public function incrementColumnInNew($increment = 1)
132     {
133         $this->columnInNew += $increment;
134
135         return $this->columnInNew;
136     }
137
138     /**
139      * @param int $increment
140      *
141      * @return int
142      */
143     public function incrementColumnInOld($increment = 1)
144     {
145         $this->columnInOld += $increment;
146
147         return $this->columnInOld;
148     }
149
150     /**
151      * @param int $increment
152      *
153      * @return int
154      */
155     public function incrementIndexInNew($increment = 1)
156     {
157         $this->indexInNew += $increment;
158
159         return $this->indexInNew;
160     }
161
162     /**
163      * @param int $increment
164      *
165      * @return int
166      */
167     public function incrementIndexInOld($increment = 1)
168     {
169         $this->indexInOld += $increment;
170
171         return $this->indexInOld;
172     }
173
174     /**
175      * @param string $type
176      * @param int    $increment
177      *
178      * @return int
179      */
180     public function incrementIndex($type, $increment = 1)
181     {
182         if ($type === 'new') {
183             return $this->incrementIndexInNew($increment);
184         }
185
186         return $this->incrementIndexInOld($increment);
187     }
188
189     /**
190      * @param string $type
191      * @param int    $increment
192      *
193      * @return int
194      */
195     public function incrementColumn($type, $increment = 1)
196     {
197         if ($type === 'new') {
198             return $this->incrementColumnInNew($increment);
199         }
200
201         return $this->incrementColumnInOld($increment);
202     }
203
204     /**
205      * @param string $type
206      *
207      * @return bool
208      */
209     public function isColumnLessThanOther($type)
210     {
211         if ($type === 'new') {
212             return $this->getColumnInNew() < $this->getColumnInOld();
213         }
214
215         return $this->getColumnInOld() < $this->getColumnInNew();
216     }
217
218     /**
219      * @param string $type
220      *
221      * @return int
222      */
223     public function getColumn($type)
224     {
225         if ($type === 'new') {
226             return $this->getColumnInNew();
227         }
228
229         return $this->getColumnInOld();
230     }
231
232     /**
233      * @param string $type
234      *
235      * @return int
236      */
237     public function getIndex($type)
238     {
239         if ($type === 'new') {
240             return $this->getIndexInNew();
241         }
242
243         return $this->getIndexInOld();
244     }
245
246     /**
247      * @return bool
248      */
249     public function areColumnsEqual()
250     {
251         return $this->getColumnInOld() === $this->getColumnInNew();
252     }
253
254     /**
255      * @return null|string
256      */
257     public function getLesserColumnType()
258     {
259         if ($this->isColumnLessThanOther('new')) {
260             return 'new';
261         } elseif ($this->isColumnLessThanOther('old')) {
262             return 'old';
263         }
264
265         return;
266     }
267 }