CodeExplorer NameScope example
public function create(string
$calledClassName, string
$declaringClassName = null
): NameScope
{ $declaringClassName ??=
$calledClassName;
$path =
explode('\\',
$calledClassName);
$calledClassName =
array_pop($path);
$declaringReflection =
new \
ReflectionClass($declaringClassName);
[$declaringNamespace,
$declaringUses] =
$this->
extractFromFullClassName($declaringReflection);
$declaringUses =
array_merge($declaringUses,
$this->
collectUses($declaringReflection));
return new NameScope($calledClassName,
$declaringNamespace,
$declaringUses);
} private function collectUses(\ReflectionClass
$reflection): array
{ $uses =
[$this->
extractFromFullClassName($reflection)[1
]];
foreach ($reflection->
getTraits() as $traitReflection) { $uses[] =
$this->
extractFromFullClassName($traitReflection)[1
];
} if (false !==
$parentClass =
$reflection->
getParentClass()) {