for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace Yoanm\ComposerConfigManager\Infrastructure\Loader;
use Symfony\Component\Filesystem\Exception\FileNotFoundException;
use Symfony\Component\Finder\Finder;
use Symfony\Component\Finder\SplFileInfo;
use Symfony\Component\Serializer\SerializerInterface;
use Yoanm\ComposerConfigManager\Application\Loader\ConfigurationLoaderInterface;
use Yoanm\ComposerConfigManager\Domain\Model\Configuration;
use Yoanm\ComposerConfigManager\Infrastructure\Serializer\Encoder\ComposerEncoder;
use Yoanm\ComposerConfigManager\Infrastructure\Writer\ConfigurationWriter;
class ConfigurationLoader implements ConfigurationLoaderInterface
{
/** @var Finder */
private $finder;
/** @var SerializerInterface */
private $serializer;
public function __construct(Finder $finder, SerializerInterface $serializer)
$this->finder = $finder;
$this->serializer = $serializer;
}
/**
* {@inheritdoc}
*/
public function fromPath($path)
/** @var SplFileInfo|null $file */
$file = null;
$file
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
$myVar = 'Value'; $higher = false; if (rand(1, 6) > 3) { $higher = true; } else { $higher = false; }
Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.
$myVar
$higher
$finder = $this->finder
->in($path)
->files()
->name(ConfigurationWriter::FILENAME)
->depth(0);
$file = $finder->getIterator()->current();
if (null === $file) {
throw new FileNotFoundException(
null,
0,
sprintf(
'File %s not found in %s',
ConfigurationWriter::FILENAME,
$path
)
);
return $this->serializer->deserialize($file->getContents(), Configuration::class, ComposerEncoder::FORMAT);
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.