for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace Transphporm;
class FilePath {
private $paths = ['.'];
private $baseDir;
public function addPath($path) {
$this->paths[] = rtrim($path, DIRECTORY_SEPARATOR);
}
public function setBaseDir($baseDir) {
$this->baseDir = $baseDir;
public function getFilePath($filePath) {
if (is_file($filePath)) return $filePath;
else if (is_file($this->baseDir . DIRECTORY_SEPARATOR . $filePath)) return $this->baseDir . DIRECTORY_SEPARATOR . $filePath;
else return $this->loadFromPaths($filePath);
throw new \Exception($filePath . ' not found in include path: ' . implode(';', $this->paths));
throw new \Exception($fi...de(';', $this->paths));
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
private function loadFromPaths($filePath) {
foreach ($this->paths as $path) {
if (is_file($path . DIRECTORY_SEPARATOR . $filePath)) return $path . DIRECTORY_SEPARATOR . $filePath;
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.