1 | <?php |
||
28 | class DiffChunk implements \ArrayAccess, \Countable, \Iterator |
||
29 | { |
||
30 | /** |
||
31 | * the cursor position |
||
32 | * |
||
33 | * @var int |
||
34 | */ |
||
35 | private $position; |
||
36 | |||
37 | /** |
||
38 | * diff start line from original file |
||
39 | * |
||
40 | * @var int |
||
41 | */ |
||
42 | private $originStartLine; |
||
43 | |||
44 | /** |
||
45 | * diff end line from original file |
||
46 | * |
||
47 | * @var int |
||
48 | */ |
||
49 | private $originEndLine; |
||
50 | |||
51 | /** |
||
52 | * diff start line from destination file |
||
53 | * |
||
54 | * @var int |
||
55 | */ |
||
56 | private $destStartLine; |
||
57 | |||
58 | /** |
||
59 | * diff end line from destination file |
||
60 | * |
||
61 | * @var int |
||
62 | */ |
||
63 | private $destEndLine; |
||
64 | |||
65 | /** |
||
66 | * hunk header line |
||
67 | * |
||
68 | * @var string |
||
69 | */ |
||
70 | private $headerLine; |
||
71 | |||
72 | /** |
||
73 | * array of lines |
||
74 | * |
||
75 | * @var array<DiffChunkLine> |
||
76 | */ |
||
77 | private $lines = []; |
||
78 | |||
79 | /** |
||
80 | * Class constructor |
||
81 | * |
||
82 | * @param array $lines output lines from git binary |
||
83 | * |
||
84 | * @throws \Exception |
||
85 | */ |
||
86 | 2 | public function __construct(array $lines) |
|
93 | |||
94 | /** |
||
95 | * Parse lines |
||
96 | * |
||
97 | * @param array $lines output lines |
||
98 | * |
||
99 | * @throws \Exception |
||
100 | */ |
||
101 | 2 | private function parseLines(array $lines): void |
|
124 | |||
125 | /** |
||
126 | * Get line numbers |
||
127 | * |
||
128 | * @param string $line a single line |
||
129 | */ |
||
130 | 2 | private function getLinesNumbers(string $line): void |
|
150 | |||
151 | /** |
||
152 | * destStartLine getter |
||
153 | * |
||
154 | * @return int |
||
155 | */ |
||
156 | public function getDestStartLine(): int |
||
160 | |||
161 | /** |
||
162 | * destEndLine getter |
||
163 | * |
||
164 | * @return int |
||
165 | */ |
||
166 | public function getDestEndLine(): int |
||
170 | |||
171 | /** |
||
172 | * originStartLine getter |
||
173 | * |
||
174 | * @return int |
||
175 | */ |
||
176 | public function getOriginStartLine(): int |
||
180 | |||
181 | /** |
||
182 | * originEndLine getter |
||
183 | * |
||
184 | * @return int |
||
185 | */ |
||
186 | public function getOriginEndLine(): int |
||
190 | |||
191 | /** |
||
192 | * Get hunk header line |
||
193 | * |
||
194 | * @return string |
||
195 | */ |
||
196 | public function getHeaderLine(): string |
||
209 | |||
210 | /** |
||
211 | * Get Lines |
||
212 | * |
||
213 | * @return array |
||
214 | */ |
||
215 | public function getLines(): array |
||
219 | |||
220 | /** |
||
221 | * ArrayAccess interface |
||
222 | * |
||
223 | * @param int $offset offset |
||
224 | * |
||
225 | * @return bool |
||
226 | */ |
||
227 | public function offsetExists($offset): bool |
||
231 | |||
232 | /** |
||
233 | * ArrayAccess interface |
||
234 | * |
||
235 | * @param int $offset offset |
||
236 | * |
||
237 | * @return DiffChunkLine|null |
||
238 | */ |
||
239 | 1 | public function offsetGet($offset) |
|
240 | { |
||
241 | 1 | return isset($this->lines[$offset]) ? $this->lines[$offset] : null; |
|
242 | } |
||
243 | |||
244 | /** |
||
245 | * ArrayAccess interface |
||
246 | * |
||
247 | * @param int|null $offset offset |
||
248 | * @param mixed $value value |
||
249 | */ |
||
250 | public function offsetSet($offset, $value): void |
||
258 | |||
259 | /** |
||
260 | * ArrayAccess interface |
||
261 | * |
||
262 | * @param int $offset offset |
||
263 | */ |
||
264 | public function offsetUnset($offset): void |
||
268 | |||
269 | /** |
||
270 | * Countable interface |
||
271 | * |
||
272 | * @return int |
||
273 | */ |
||
274 | 1 | public function count(): int |
|
275 | { |
||
276 | 1 | return count($this->lines); |
|
277 | } |
||
278 | |||
279 | /** |
||
280 | * Iterator interface |
||
281 | * |
||
282 | * @return mixed |
||
283 | */ |
||
284 | 1 | public function current() |
|
288 | |||
289 | /** |
||
290 | * Iterator interface |
||
291 | */ |
||
292 | 1 | public function next(): void |
|
296 | |||
297 | /** |
||
298 | * Iterator interface |
||
299 | * |
||
300 | * @return int |
||
301 | */ |
||
302 | public function key(): int |
||
306 | |||
307 | /** |
||
308 | * Iterator interface |
||
309 | * |
||
310 | * @return bool |
||
311 | */ |
||
312 | 1 | public function valid(): bool |
|
316 | |||
317 | /** |
||
318 | * Iterator interface |
||
319 | */ |
||
320 | 1 | public function rewind(): void |
|
324 | } |
||
325 |
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.