for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
/*
* This file is part of CacheTool.
*
* (c) Samuel Gordalina <[email protected]>
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace CacheTool\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
class PHPFileCommand extends AbstractCommand
{
/**
* {@inheritdoc}
protected function configure()
$this
->setName('php:file')
->setDescription('Run a specified file')
->addArgument('file', InputArgument::REQUIRED)
->setHelp('');
}
protected function execute(InputInterface $input, OutputInterface $output): int
$file = $input->getArgument('file');
if (!file_exists($file)) {
throw new \RuntimeException("file not found");
return 1;
This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.
Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.
return
die
exit
function fx() { try { doSomething(); return true; } catch (\Exception $e) { return false; } return false; }
In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.
return false
$code = file_get_contents($file);
$code = str_replace('<?php','',$code);
$success = $this->getCacheTool()->_eval($code);
$output->writeln(sprintf("<comment>File Output:\n <info>%s</info></comment>", $success));
return 0;
This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.
Unreachable code is most often the result of
return
,die
orexit
statements that have been added for debug purposes.In the above example, the last
return false
will never be executed, because a return statement has already been met in every possible execution path.