1 | <?php |
||
30 | class DiffObject implements \ArrayAccess, \Countable, \Iterator |
||
31 | { |
||
32 | public const MODE_INDEX = 'index'; |
||
33 | public const MODE_MODE = 'mode'; |
||
34 | public const MODE_NEW_FILE = 'new_file'; |
||
35 | public const MODE_DELETED_FILE = 'deleted_file'; |
||
36 | public const MODE_RENAMED = 'renamed_file'; |
||
37 | |||
38 | /** |
||
39 | * the cursor position |
||
40 | * |
||
41 | * @var int|null |
||
42 | */ |
||
43 | private $position; |
||
44 | |||
45 | /** |
||
46 | * the original file path for the diff object |
||
47 | * |
||
48 | * @var string|null |
||
49 | */ |
||
50 | private $originalPath; |
||
51 | |||
52 | /** |
||
53 | * the destination path for the diff object |
||
54 | * |
||
55 | * @var string|null |
||
56 | */ |
||
57 | private $destinationPath; |
||
58 | |||
59 | /** |
||
60 | * rename similarity index |
||
61 | * |
||
62 | * @var int|null |
||
63 | */ |
||
64 | private $similarityIndex; |
||
65 | |||
66 | /** |
||
67 | * the diff mode |
||
68 | * |
||
69 | * @var string|null |
||
70 | */ |
||
71 | private $mode; |
||
72 | |||
73 | /** |
||
74 | * the diff chunks |
||
75 | * |
||
76 | * @var array |
||
77 | */ |
||
78 | private $chunks = []; |
||
79 | |||
80 | /** |
||
81 | * Class constructor |
||
82 | * |
||
83 | * @param array $lines output lines for the diff |
||
84 | * |
||
85 | * @throws \InvalidArgumentException |
||
86 | */ |
||
87 | 2 | public function __construct(array $lines) |
|
115 | |||
116 | /** |
||
117 | * toString magic method |
||
118 | * |
||
119 | * @return string|null |
||
120 | */ |
||
121 | public function __toString(): ?string |
||
125 | |||
126 | /** |
||
127 | * Find the diff chunks |
||
128 | * |
||
129 | * @param array $lines output lines for the diff |
||
130 | * |
||
131 | * @throws \InvalidArgumentException |
||
132 | */ |
||
133 | 2 | private function findChunks(array $lines): void |
|
143 | |||
144 | /** |
||
145 | * look for the path in the line |
||
146 | * |
||
147 | * @param string $line line content |
||
148 | */ |
||
149 | 2 | private function findPath(string $line): void |
|
157 | |||
158 | /** |
||
159 | * find the line mode |
||
160 | * |
||
161 | * @param string $line line content |
||
162 | */ |
||
163 | 2 | private function findMode(string $line): void |
|
181 | |||
182 | /** |
||
183 | * look for similarity index in the line |
||
184 | * |
||
185 | * @param string $line line content |
||
186 | */ |
||
187 | private function findSimilarityIndex(string $line): void |
||
194 | |||
195 | /** |
||
196 | * chunks getter |
||
197 | * |
||
198 | * @return array |
||
199 | */ |
||
200 | public function getChunks(): array |
||
204 | |||
205 | /** |
||
206 | * destinationPath getter |
||
207 | * |
||
208 | * @return string |
||
209 | */ |
||
210 | public function getDestinationPath(): string |
||
214 | |||
215 | /** |
||
216 | * mode getter |
||
217 | * |
||
218 | * @return string |
||
219 | */ |
||
220 | public function getMode(): string |
||
224 | |||
225 | /** |
||
226 | * originalPath getter |
||
227 | * |
||
228 | * @return string |
||
229 | */ |
||
230 | public function getOriginalPath(): string |
||
234 | |||
235 | /** |
||
236 | * Check if path has changed (file was renamed) |
||
237 | * |
||
238 | * @return bool |
||
239 | */ |
||
240 | 2 | public function hasPathChanged(): bool |
|
244 | |||
245 | /** |
||
246 | * Get similarity index |
||
247 | * |
||
248 | * @return int |
||
249 | * @throws \RuntimeException if not a rename |
||
250 | */ |
||
251 | public function getSimilarityIndex(): int |
||
259 | |||
260 | /** |
||
261 | * ArrayAccess interface |
||
262 | * |
||
263 | * @param int $offset offset |
||
264 | * |
||
265 | * @return bool |
||
266 | */ |
||
267 | public function offsetExists($offset): bool |
||
271 | |||
272 | /** |
||
273 | * ArrayAccess interface |
||
274 | * |
||
275 | * @param int $offset offset |
||
276 | * |
||
277 | * @return DiffChunk|null |
||
278 | */ |
||
279 | 1 | public function offsetGet($offset) |
|
283 | |||
284 | /** |
||
285 | * ArrayAccess interface |
||
286 | * |
||
287 | * @param int|null $offset offset |
||
288 | * @param mixed $value value |
||
289 | */ |
||
290 | public function offsetSet($offset, $value): void |
||
298 | |||
299 | /** |
||
300 | * ArrayAccess interface |
||
301 | * |
||
302 | * @param int $offset offset |
||
303 | */ |
||
304 | public function offsetUnset($offset): void |
||
308 | |||
309 | /** |
||
310 | * Countable interface |
||
311 | * |
||
312 | * @return int |
||
313 | */ |
||
314 | 1 | public function count(): int |
|
315 | { |
||
316 | 1 | return count($this->chunks); |
|
317 | } |
||
318 | |||
319 | /** |
||
320 | * Iterator interface |
||
321 | * |
||
322 | * @return mixed |
||
323 | */ |
||
324 | public function current() |
||
328 | |||
329 | /** |
||
330 | * Iterator interface |
||
331 | */ |
||
332 | public function next(): void |
||
336 | |||
337 | /** |
||
338 | * Iterator interface |
||
339 | * |
||
340 | * @return int |
||
341 | */ |
||
342 | public function key(): int |
||
346 | |||
347 | /** |
||
348 | * Iterator interface |
||
349 | * |
||
350 | * @return bool |
||
351 | */ |
||
352 | public function valid(): bool |
||
356 | |||
357 | /** |
||
358 | * Iterator interface |
||
359 | */ |
||
360 | public function rewind(): void |
||
364 | } |
||
365 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..