| Conditions | 3 |
| Paths | 4 |
| Total Lines | 21 |
| Code Lines | 12 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 13 |
| CRAP Score | 3 |
| Changes | 0 | ||
| 1 | <?php declare(strict_types=1); |
||
| 20 | 4 | public function getPlaceInFile(int $linesBefore = 4, int $linesAfter = 4): array |
|
| 21 | { |
||
| 22 | 4 | $context = []; |
|
| 23 | |||
| 24 | 4 | $offset = $this->line - $linesBefore - 1; |
|
| 25 | |||
| 26 | 4 | if ($offset < 0) { |
|
| 27 | 2 | $linesBefore = 0; |
|
| 28 | 2 | $offset = 0; |
|
| 29 | } |
||
| 30 | |||
| 31 | 4 | $file = new SplFileObject($this->file, 'rb'); |
|
| 32 | 4 | $iterator = new LimitIterator($file, $offset, $linesBefore + $linesAfter + 1); |
|
| 33 | 4 | $index = $offset + 1; |
|
| 34 | |||
| 35 | 4 | foreach ($iterator as $text) { |
|
| 36 | 4 | $context[$index] = $text; |
|
| 37 | 4 | $index++; |
|
| 38 | } |
||
| 39 | |||
| 40 | 4 | return $context; |
|
| 41 | } |
||
| 43 |