| Conditions | 2 |
| Paths | 2 |
| Total Lines | 13 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 55 | private function addOrUpdateIncrement(string $string): string |
||
| 56 | { |
||
| 57 | $pattern = '/-(\d+$)/'; |
||
| 58 | $matches = []; |
||
| 59 | |||
| 60 | if (! preg_match($pattern, $string, $matches)) { |
||
| 61 | return $string.'-1'; |
||
| 62 | } |
||
| 63 | |||
| 64 | $increment = $matches[1] + 1; |
||
| 65 | |||
| 66 | return preg_replace($pattern, "-{$increment}", $string); |
||
| 67 | } |
||
| 68 | } |
||
| 69 |
This error can happen if you refactor code and forget to move the variable initialization.
Let’s take a look at a simple example:
The above code is perfectly fine. Now imagine that we re-order the statements:
In that case,
$xwould be read before it is initialized. This was a very basic example, however the principle is the same for the found issue.