1 | <?php |
||
27 | class DiffChunk implements \ArrayAccess, \Countable, \Iterator |
||
28 | { |
||
29 | /** |
||
30 | * the cursor position |
||
31 | * |
||
32 | * @var int |
||
33 | */ |
||
34 | private $position; |
||
35 | |||
36 | /** |
||
37 | * diff start line from original file |
||
38 | * |
||
39 | * @var int |
||
40 | */ |
||
41 | private $originStartLine; |
||
42 | |||
43 | /** |
||
44 | * diff end line from original file |
||
45 | * |
||
46 | * @var int |
||
47 | */ |
||
48 | private $originEndLine; |
||
49 | |||
50 | /** |
||
51 | * diff start line from destination file |
||
52 | * |
||
53 | * @var int |
||
54 | */ |
||
55 | private $destStartLine; |
||
56 | |||
57 | /** |
||
58 | * diff end line from destination file |
||
59 | * |
||
60 | * @var int |
||
61 | */ |
||
62 | private $destEndLine; |
||
63 | |||
64 | /** |
||
65 | * hunk header line |
||
66 | * |
||
67 | * @var string |
||
68 | */ |
||
69 | private $headerLine; |
||
70 | |||
71 | /** |
||
72 | * array of lines |
||
73 | * |
||
74 | * @var array |
||
75 | */ |
||
76 | private $lines; |
||
77 | |||
78 | /** |
||
79 | * Class constructor |
||
80 | * |
||
81 | * @param array $lines output lines from git binary |
||
82 | * |
||
83 | * @throws \Exception |
||
84 | */ |
||
85 | 2 | public function __construct($lines) |
|
92 | |||
93 | /** |
||
94 | * Parse lines |
||
95 | * |
||
96 | * @param array $lines output lines |
||
97 | * |
||
98 | * @throws \Exception |
||
99 | */ |
||
100 | 2 | private function parseLines($lines) |
|
129 | |||
130 | /** |
||
131 | * Get line numbers |
||
132 | * |
||
133 | * @param string $line a single line |
||
134 | */ |
||
135 | 2 | private function getLinesNumbers($line) |
|
154 | |||
155 | /** |
||
156 | * destStartLine getter |
||
157 | * |
||
158 | * @return int |
||
159 | */ |
||
160 | public function getDestStartLine() |
||
164 | |||
165 | /** |
||
166 | * destEndLine getter |
||
167 | * |
||
168 | * @return int |
||
169 | */ |
||
170 | public function getDestEndLine() |
||
174 | |||
175 | /** |
||
176 | * originStartLine getter |
||
177 | * |
||
178 | * @return int |
||
179 | */ |
||
180 | public function getOriginStartLine() |
||
184 | |||
185 | /** |
||
186 | * originEndLine getter |
||
187 | * |
||
188 | * @return int |
||
189 | */ |
||
190 | public function getOriginEndLine() |
||
194 | |||
195 | /** |
||
196 | * Get hunk header line |
||
197 | * |
||
198 | * @return string |
||
199 | */ |
||
200 | public function getHeaderLine() |
||
213 | |||
214 | /** |
||
215 | * Get Lines |
||
216 | * |
||
217 | * @return array |
||
218 | */ |
||
219 | public function getLines() |
||
223 | |||
224 | /** |
||
225 | * ArrayAccess interface |
||
226 | * |
||
227 | * @param int $offset offset |
||
228 | * |
||
229 | * @return bool |
||
230 | */ |
||
231 | public function offsetExists($offset) |
||
235 | |||
236 | /** |
||
237 | * ArrayAccess interface |
||
238 | * |
||
239 | * @param int $offset offset |
||
240 | * |
||
241 | * @return null |
||
242 | */ |
||
243 | public function offsetGet($offset) |
||
247 | |||
248 | /** |
||
249 | * ArrayAccess interface |
||
250 | * |
||
251 | * @param int $offset offset |
||
252 | * @param mixed $value value |
||
253 | */ |
||
254 | public function offsetSet($offset, $value) |
||
262 | |||
263 | /** |
||
264 | * ArrayAccess interface |
||
265 | * |
||
266 | * @param int $offset offset |
||
267 | */ |
||
268 | public function offsetUnset($offset) |
||
272 | |||
273 | /** |
||
274 | * Countable interface |
||
275 | * |
||
276 | * @return int|void |
||
277 | */ |
||
278 | 1 | public function count() |
|
282 | |||
283 | /** |
||
284 | * Iterator interface |
||
285 | * |
||
286 | * @return mixed |
||
287 | */ |
||
288 | 1 | public function current() |
|
292 | |||
293 | /** |
||
294 | * Iterator interface |
||
295 | */ |
||
296 | 1 | public function next() |
|
300 | |||
301 | /** |
||
302 | * Iterator interface |
||
303 | * |
||
304 | * @return int |
||
305 | */ |
||
306 | public function key() |
||
310 | |||
311 | /** |
||
312 | * Iterator interface |
||
313 | * |
||
314 | * @return bool |
||
315 | */ |
||
316 | 1 | public function valid() |
|
320 | |||
321 | /** |
||
322 | * Iterator interface |
||
323 | */ |
||
324 | 1 | public function rewind() |
|
328 | } |
||
329 |
This check looks for assignments to scalar types that may be of the wrong type.
To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.