for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
declare(strict_types=1);
/*
* This file is part of the humbug/php-scoper package.
*
* Copyright (c) 2017 Théo FIDRY <[email protected]>,
* Pádraic Brady <[email protected]>
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Humbug\PhpScoper;
use ReflectionException;
use ReflectionFunction;
use Roave\BetterReflection\Reflector\ClassReflector;
use Roave\BetterReflection\Reflector\Exception\IdentifierNotFound;
use Roave\BetterReflection\Reflector\FunctionReflector;
final class Reflector
{
private $classReflector;
private $functionReflector;
public function __construct(ClassReflector $classReflector, FunctionReflector $functionReflector)
$this->classReflector = $classReflector;
$this->functionReflector = $functionReflector;
}
public function isClassInternal(string $name): bool
try {
return $this->classReflector->reflect($name)->isInternal();
} catch (IdentifierNotFound $exception) {
return false;
public function isFunctionInternal(string $name): bool
return (new ReflectionFunction($name))->isInternal();
// TODO: leverage Better Reflection instead
return $this->functionReflector->reflect($name)->isInternal();
return $this->functionRe...t($name)->isInternal();
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
} catch (ReflectionException $exception) {
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.