| Conditions | 8 |
| Paths | 10 |
| Total Lines | 30 |
| Code Lines | 17 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 14 | public function __invoke(UriInterface $uri) |
||
| 15 | { |
||
| 16 | $basePath = $uri->getPath(); |
||
| 17 | if ($path === $basePath) { |
||
|
|
|||
| 18 | return ''; |
||
| 19 | } |
||
| 20 | |||
| 21 | $baseParts = explode('/', $basePath, -1); |
||
| 22 | $pathParts = explode('/', $path); |
||
| 23 | |||
| 24 | foreach ($baseParts as $i => $segment) { |
||
| 25 | if (isset($pathParts[$i]) && $segment === $pathParts[$i]) { |
||
| 26 | unset($baseParts[$i], $pathParts[$i]); |
||
| 27 | } else { |
||
| 28 | break; |
||
| 29 | } |
||
| 30 | } |
||
| 31 | |||
| 32 | $path = str_repeat('../', count($baseParts)) . implode('/', $pathParts); |
||
| 33 | |||
| 34 | if (empty($path)) { |
||
| 35 | return './'; |
||
| 36 | } |
||
| 37 | |||
| 38 | if (empty($baseParts) && false !== strpos(current($pathParts), ':')) { |
||
| 39 | $path = "./{$path}"; |
||
| 40 | } |
||
| 41 | |||
| 42 | return $path; |
||
| 43 | } |
||
| 44 | } |
||
| 45 |
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.