mirror of
https://github.com/rectorphp/rector.git
synced 2024-05-28 23:10:51 +00:00
6c20d257e3
d3d18d442c
keep relative paths
54 lines
1.4 KiB
PHP
54 lines
1.4 KiB
PHP
<?php
|
|
|
|
declare (strict_types=1);
|
|
namespace RectorPrefix202209\Symplify\PackageBuilder\Reflection;
|
|
|
|
use ReflectionClass;
|
|
/**
|
|
* @api
|
|
*/
|
|
final class ClassLikeExistenceChecker
|
|
{
|
|
/**
|
|
* @var string[]
|
|
*/
|
|
private $sensitiveExistingClasses = [];
|
|
/**
|
|
* @var string[]
|
|
*/
|
|
private $sensitiveNonExistingClasses = [];
|
|
public function doesClassLikeExist(string $classLike) : bool
|
|
{
|
|
if (\class_exists($classLike)) {
|
|
return \true;
|
|
}
|
|
if (\interface_exists($classLike)) {
|
|
return \true;
|
|
}
|
|
return \trait_exists($classLike);
|
|
}
|
|
/**
|
|
* @api
|
|
*/
|
|
public function doesClassLikeInsensitiveExists(string $classLikeName) : bool
|
|
{
|
|
if (!$this->doesClassLikeExist($classLikeName)) {
|
|
return \false;
|
|
}
|
|
// already known values
|
|
if (\in_array($classLikeName, $this->sensitiveExistingClasses, \true)) {
|
|
return \true;
|
|
}
|
|
if (\in_array($classLikeName, $this->sensitiveNonExistingClasses, \true)) {
|
|
return \false;
|
|
}
|
|
$reflectionClass = new ReflectionClass($classLikeName);
|
|
if ($classLikeName !== $reflectionClass->getName()) {
|
|
$this->sensitiveNonExistingClasses[] = $classLikeName;
|
|
return \false;
|
|
}
|
|
$this->sensitiveExistingClasses[] = $classLikeName;
|
|
return \true;
|
|
}
|
|
}
|