for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace AlexMasterov\TwigExtension;
use Psr\Http\Message\UriInterface;
final class RelativePathGenerator
{
/**
* @param UriInterface $uri
*
* @return string
*/
public function __invoke(UriInterface $uri)
$basePath = $uri->getPath();
if ($path === $basePath) {
$path
This error can happen if you refactor code and forget to move the variable initialization.
Let’s take a look at a simple example:
function someFunction() { $x = 5; echo $x; }
The above code is perfectly fine. Now imagine that we re-order the statements:
function someFunction() { echo $x; $x = 5; }
In that case, $x would be read before it is initialized. This was a very basic example, however the principle is the same for the found issue.
$x
return '';
}
$baseParts = explode('/', $basePath, -1);
$pathParts = explode('/', $path);
foreach ($baseParts as $i => $segment) {
if (isset($pathParts[$i]) && $segment === $pathParts[$i]) {
unset($baseParts[$i], $pathParts[$i]);
} else {
break;
$path = str_repeat('../', count($baseParts)) . implode('/', $pathParts);
if (empty($path)) {
return './';
if (empty($baseParts) && false !== strpos(current($pathParts), ':')) {
$path = "./{$path}";
return $path;
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,
$x
would be read before it is initialized. This was a very basic example, however the principle is the same for the found issue.