Cancelled
Push — master ( 5c013f...948458 )
by Josh
322:57 queued 322:57
created

DiffRowPosition::getIndexInNew()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

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