| Conditions | 2 |
| Paths | 2 |
| Total Lines | 14 |
| Code Lines | 6 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 7 |
| CRAP Score | 2 |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 28 | 5 | public static function insertAt(array &$list, int $index, mixed $value): void |
|
| 29 | { |
||
| 30 | 5 | $tailIdx = count($list) - 1; |
|
| 31 | |||
| 32 | // 1. Move values until the end of original list |
||
| 33 | 5 | $prevValue = $value; |
|
| 34 | 5 | while ($index <= $tailIdx) { |
|
| 35 | // Backup original value at $index + replace original value by the previous value |
||
| 36 | 3 | [$prevValue, $list[$index]] = [$list[$index], $prevValue]; // @phpstan-ignore parameterByRef.type |
|
| 37 | 3 | ++$index; |
|
| 38 | } |
||
| 39 | |||
| 40 | // 2. Append the original tail value at the end of the list (=new index !) |
||
| 41 | 5 | $list[$index] = $prevValue; // @phpstan-ignore parameterByRef.type |
|
| 42 | } |
||
| 44 |