2018-01-21 19:38:51 +01:00
|
|
|
<?php
|
2018-11-12 16:46:55 +01:00
|
|
|
namespace Psalm\Internal\Codebase;
|
2018-01-21 19:38:51 +01:00
|
|
|
|
2019-07-05 22:24:00 +02:00
|
|
|
use function array_merge;
|
2018-01-21 19:38:51 +01:00
|
|
|
use Psalm\Codebase;
|
2019-07-05 22:24:00 +02:00
|
|
|
use Psalm\Internal\Analyzer\ClassLikeAnalyzer;
|
2018-11-06 03:57:36 +01:00
|
|
|
use Psalm\Internal\Provider\ClassLikeStorageProvider;
|
2018-05-12 00:35:02 +02:00
|
|
|
use Psalm\Storage\FunctionLikeParameter;
|
2018-01-21 19:38:51 +01:00
|
|
|
use Psalm\Storage\FunctionLikeStorage;
|
|
|
|
use Psalm\Storage\MethodStorage;
|
|
|
|
use Psalm\Storage\PropertyStorage;
|
|
|
|
use Psalm\Type;
|
2019-06-26 22:52:29 +02:00
|
|
|
use function strtolower;
|
2018-01-21 19:38:51 +01:00
|
|
|
|
2018-02-09 23:51:49 +01:00
|
|
|
/**
|
|
|
|
* @internal
|
|
|
|
*
|
|
|
|
* Handles information gleaned from class and function reflection
|
|
|
|
*/
|
2018-01-21 19:38:51 +01:00
|
|
|
class Reflection
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @var ClassLikeStorageProvider
|
|
|
|
*/
|
|
|
|
private $storage_provider;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var Codebase
|
|
|
|
*/
|
|
|
|
private $codebase;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var array<string, FunctionLikeStorage>
|
|
|
|
*/
|
|
|
|
private static $builtin_functions = [];
|
|
|
|
|
|
|
|
public function __construct(ClassLikeStorageProvider $storage_provider, Codebase $codebase)
|
|
|
|
{
|
|
|
|
$this->storage_provider = $storage_provider;
|
|
|
|
$this->codebase = $codebase;
|
|
|
|
self::$builtin_functions = [];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return void
|
|
|
|
*/
|
2018-01-28 18:01:51 +01:00
|
|
|
public function registerClass(\ReflectionClass $reflected_class)
|
|
|
|
{
|
2018-01-21 19:38:51 +01:00
|
|
|
$class_name = $reflected_class->name;
|
|
|
|
|
|
|
|
if ($class_name === 'LibXMLError') {
|
|
|
|
$class_name = 'libXMLError';
|
|
|
|
}
|
|
|
|
|
|
|
|
$class_name_lower = strtolower($class_name);
|
|
|
|
|
|
|
|
try {
|
|
|
|
$this->storage_provider->get($class_name_lower);
|
|
|
|
|
|
|
|
return;
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
// this is fine
|
|
|
|
}
|
|
|
|
|
|
|
|
$reflected_parent_class = $reflected_class->getParentClass();
|
|
|
|
|
|
|
|
$storage = $this->storage_provider->create($class_name);
|
|
|
|
$storage->abstract = $reflected_class->isAbstract();
|
2019-03-07 17:16:40 +01:00
|
|
|
$storage->is_interface = $reflected_class->isInterface();
|
2018-01-21 19:38:51 +01:00
|
|
|
|
2018-09-26 00:37:24 +02:00
|
|
|
$storage->potential_declaring_method_ids['__construct'][$class_name_lower . '::__construct'] = true;
|
|
|
|
|
2018-01-21 19:38:51 +01:00
|
|
|
if ($reflected_parent_class) {
|
|
|
|
$parent_class_name = $reflected_parent_class->getName();
|
2018-01-28 18:01:51 +01:00
|
|
|
$this->registerClass($reflected_parent_class);
|
2018-01-21 19:38:51 +01:00
|
|
|
|
|
|
|
$parent_storage = $this->storage_provider->get($parent_class_name);
|
|
|
|
|
|
|
|
$this->registerInheritedMethods($class_name, $parent_class_name);
|
|
|
|
$this->registerInheritedProperties($class_name, $parent_class_name);
|
|
|
|
|
|
|
|
$storage->class_implements = $parent_storage->class_implements;
|
|
|
|
|
|
|
|
$storage->public_class_constants = $parent_storage->public_class_constants;
|
|
|
|
$storage->protected_class_constants = $parent_storage->protected_class_constants;
|
2018-02-04 00:52:35 +01:00
|
|
|
$parent_class_name_lc = strtolower($parent_class_name);
|
|
|
|
$storage->parent_classes = array_merge(
|
2019-03-08 23:35:09 +01:00
|
|
|
[$parent_class_name_lc => $parent_class_name],
|
2018-02-04 00:52:35 +01:00
|
|
|
$parent_storage->parent_classes
|
|
|
|
);
|
2018-01-21 19:38:51 +01:00
|
|
|
|
|
|
|
$storage->used_traits = $parent_storage->used_traits;
|
|
|
|
}
|
|
|
|
|
|
|
|
$class_properties = $reflected_class->getProperties();
|
|
|
|
|
2018-02-04 18:34:08 +01:00
|
|
|
$public_mapped_properties = PropertyMap::inPropertyMap($class_name)
|
|
|
|
? PropertyMap::getPropertyMap()[strtolower($class_name)]
|
2018-01-21 19:38:51 +01:00
|
|
|
: [];
|
|
|
|
|
|
|
|
/** @var \ReflectionProperty $class_property */
|
|
|
|
foreach ($class_properties as $class_property) {
|
|
|
|
$property_name = $class_property->getName();
|
|
|
|
$storage->properties[$property_name] = new PropertyStorage();
|
|
|
|
|
|
|
|
$storage->properties[$property_name]->type = Type::getMixed();
|
|
|
|
|
|
|
|
if ($class_property->isStatic()) {
|
|
|
|
$storage->properties[$property_name]->is_static = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($class_property->isPublic()) {
|
2018-11-06 03:57:36 +01:00
|
|
|
$storage->properties[$property_name]->visibility = ClassLikeAnalyzer::VISIBILITY_PUBLIC;
|
2018-01-21 19:38:51 +01:00
|
|
|
} elseif ($class_property->isProtected()) {
|
2018-11-06 03:57:36 +01:00
|
|
|
$storage->properties[$property_name]->visibility = ClassLikeAnalyzer::VISIBILITY_PROTECTED;
|
2018-01-21 19:38:51 +01:00
|
|
|
} elseif ($class_property->isPrivate()) {
|
2018-11-06 03:57:36 +01:00
|
|
|
$storage->properties[$property_name]->visibility = ClassLikeAnalyzer::VISIBILITY_PRIVATE;
|
2018-01-21 19:38:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
$property_id = (string)$class_property->class . '::$' . $property_name;
|
|
|
|
|
2018-07-22 01:56:26 +02:00
|
|
|
$storage->declaring_property_ids[$property_name] = (string)$class_property->class;
|
2018-01-21 19:38:51 +01:00
|
|
|
$storage->appearing_property_ids[$property_name] = $property_id;
|
|
|
|
|
|
|
|
if (!$class_property->isPrivate()) {
|
|
|
|
$storage->inheritable_property_ids[$property_name] = $property_id;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// have to do this separately as there can be new properties here
|
|
|
|
foreach ($public_mapped_properties as $property_name => $type) {
|
|
|
|
if (!isset($storage->properties[$property_name])) {
|
|
|
|
$storage->properties[$property_name] = new PropertyStorage();
|
2018-11-06 03:57:36 +01:00
|
|
|
$storage->properties[$property_name]->visibility = ClassLikeAnalyzer::VISIBILITY_PUBLIC;
|
2018-01-21 19:38:51 +01:00
|
|
|
|
|
|
|
$property_id = $class_name . '::$' . $property_name;
|
|
|
|
|
2018-07-22 01:56:26 +02:00
|
|
|
$storage->declaring_property_ids[$property_name] = $class_name;
|
2018-01-21 19:38:51 +01:00
|
|
|
$storage->appearing_property_ids[$property_name] = $property_id;
|
|
|
|
$storage->inheritable_property_ids[$property_name] = $property_id;
|
|
|
|
}
|
|
|
|
|
|
|
|
$storage->properties[$property_name]->type = Type::parseString($type);
|
|
|
|
}
|
|
|
|
|
|
|
|
/** @var array<string, int|string|float|null|array> */
|
|
|
|
$class_constants = $reflected_class->getConstants();
|
|
|
|
|
|
|
|
foreach ($class_constants as $name => $value) {
|
2018-11-06 03:57:36 +01:00
|
|
|
$storage->public_class_constants[$name] = ClassLikeAnalyzer::getTypeFromValue($value);
|
2018-01-21 19:38:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if ($reflected_class->isInterface()) {
|
2018-02-04 00:52:35 +01:00
|
|
|
$this->codebase->classlikes->addFullyQualifiedInterfaceName($class_name);
|
2018-01-21 19:38:51 +01:00
|
|
|
} elseif ($reflected_class->isTrait()) {
|
2018-02-04 00:52:35 +01:00
|
|
|
$this->codebase->classlikes->addFullyQualifiedTraitName($class_name);
|
2018-01-21 19:38:51 +01:00
|
|
|
} else {
|
2018-02-04 00:52:35 +01:00
|
|
|
$this->codebase->classlikes->addFullyQualifiedClassName($class_name);
|
2018-01-21 19:38:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
$reflection_methods = $reflected_class->getMethods(
|
2019-06-29 18:32:44 +02:00
|
|
|
(\ReflectionMethod::IS_PUBLIC | \ReflectionMethod::IS_PROTECTED)
|
2018-01-21 19:38:51 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
if ($class_name_lower === 'generator') {
|
2019-01-10 18:13:49 +01:00
|
|
|
$storage->template_types = [
|
2019-03-22 20:59:10 +01:00
|
|
|
'TKey' => ['Generator' => [Type::getMixed()]],
|
|
|
|
'TValue' => ['Generator' => [Type::getMixed()]],
|
2019-01-10 18:13:49 +01:00
|
|
|
];
|
2018-01-21 19:38:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
$interfaces = $reflected_class->getInterfaces();
|
|
|
|
|
|
|
|
/** @var \ReflectionClass $interface */
|
|
|
|
foreach ($interfaces as $interface) {
|
|
|
|
$interface_name = $interface->getName();
|
2018-01-28 18:01:51 +01:00
|
|
|
$this->registerClass($interface);
|
2018-01-21 19:38:51 +01:00
|
|
|
|
|
|
|
if ($reflected_class->isInterface()) {
|
|
|
|
$storage->parent_interfaces[strtolower($interface_name)] = $interface_name;
|
|
|
|
} else {
|
|
|
|
$storage->class_implements[strtolower($interface_name)] = $interface_name;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/** @var \ReflectionMethod $reflection_method */
|
|
|
|
foreach ($reflection_methods as $reflection_method) {
|
|
|
|
$method_reflection_class = $reflection_method->getDeclaringClass();
|
|
|
|
|
2018-01-28 18:01:51 +01:00
|
|
|
$this->registerClass($method_reflection_class);
|
2018-01-21 19:38:51 +01:00
|
|
|
|
|
|
|
$this->extractReflectionMethodInfo($reflection_method);
|
|
|
|
|
2019-04-09 21:06:10 +02:00
|
|
|
if ($reflection_method->class !== $class_name
|
|
|
|
&& ($class_name !== 'SoapFault' || $reflection_method->name !== '__construct')
|
|
|
|
) {
|
2018-02-04 00:52:35 +01:00
|
|
|
$this->codebase->methods->setDeclaringMethodId(
|
2018-01-21 19:38:51 +01:00
|
|
|
$class_name . '::' . strtolower($reflection_method->name),
|
|
|
|
$reflection_method->class . '::' . strtolower($reflection_method->name)
|
|
|
|
);
|
|
|
|
|
2018-02-04 00:52:35 +01:00
|
|
|
$this->codebase->methods->setAppearingMethodId(
|
2018-01-21 19:38:51 +01:00
|
|
|
$class_name . '::' . strtolower($reflection_method->name),
|
|
|
|
$reflection_method->class . '::' . strtolower($reflection_method->name)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param \ReflectionMethod $method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function extractReflectionMethodInfo(\ReflectionMethod $method)
|
|
|
|
{
|
|
|
|
$method_name = strtolower($method->getName());
|
|
|
|
|
|
|
|
$class_storage = $this->storage_provider->get($method->class);
|
|
|
|
|
|
|
|
if (isset($class_storage->methods[strtolower($method_name)])) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$method_id = $method->class . '::' . $method_name;
|
|
|
|
|
|
|
|
$storage = $class_storage->methods[strtolower($method_name)] = new MethodStorage();
|
|
|
|
|
|
|
|
$storage->cased_name = $method->name;
|
2019-01-28 05:12:40 +01:00
|
|
|
$storage->defining_fqcln = $method->class;
|
2018-01-21 19:38:51 +01:00
|
|
|
|
|
|
|
if (strtolower((string)$method->name) === strtolower((string)$method->class)) {
|
2018-02-04 00:52:35 +01:00
|
|
|
$this->codebase->methods->setDeclaringMethodId(
|
2018-01-21 19:38:51 +01:00
|
|
|
$method->class . '::__construct',
|
|
|
|
$method->class . '::' . $method_name
|
|
|
|
);
|
2018-02-04 00:52:35 +01:00
|
|
|
$this->codebase->methods->setAppearingMethodId(
|
2018-01-21 19:38:51 +01:00
|
|
|
$method->class . '::__construct',
|
|
|
|
$method->class . '::' . $method_name
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
$declaring_class = $method->getDeclaringClass();
|
|
|
|
|
|
|
|
$storage->is_static = $method->isStatic();
|
2018-07-22 02:50:42 +02:00
|
|
|
$storage->abstract = $method->isAbstract();
|
|
|
|
|
2018-01-21 19:38:51 +01:00
|
|
|
$class_storage->declaring_method_ids[$method_name] =
|
|
|
|
$declaring_class->name . '::' . strtolower((string)$method->getName());
|
|
|
|
|
|
|
|
$class_storage->inheritable_method_ids[$method_name] = $class_storage->declaring_method_ids[$method_name];
|
|
|
|
$class_storage->appearing_method_ids[$method_name] = $class_storage->declaring_method_ids[$method_name];
|
|
|
|
$class_storage->overridden_method_ids[$method_name] = [];
|
|
|
|
|
|
|
|
$storage->visibility = $method->isPrivate()
|
2018-11-06 03:57:36 +01:00
|
|
|
? ClassLikeAnalyzer::VISIBILITY_PRIVATE
|
|
|
|
: ($method->isProtected() ? ClassLikeAnalyzer::VISIBILITY_PROTECTED : ClassLikeAnalyzer::VISIBILITY_PUBLIC);
|
2018-01-21 19:38:51 +01:00
|
|
|
|
2019-06-15 22:10:48 +02:00
|
|
|
$callables = CallMap::getCallablesFromCallMap($method_id);
|
|
|
|
|
|
|
|
if ($callables && $callables[0]->params !== null && $callables[0]->return_type !== null) {
|
|
|
|
$storage->params = [];
|
|
|
|
|
|
|
|
foreach ($callables[0]->params as $param) {
|
|
|
|
if ($param->type) {
|
|
|
|
$param->type->queueClassLikesForScanning($this->codebase);
|
|
|
|
}
|
|
|
|
}
|
2018-01-21 19:38:51 +01:00
|
|
|
|
2019-06-15 22:10:48 +02:00
|
|
|
$storage->params = $callables[0]->params;
|
|
|
|
|
|
|
|
$storage->return_type = $callables[0]->return_type;
|
|
|
|
$storage->return_type->queueClassLikesForScanning($this->codebase);
|
|
|
|
} else {
|
2018-01-21 19:38:51 +01:00
|
|
|
$params = $method->getParameters();
|
|
|
|
|
|
|
|
$storage->params = [];
|
|
|
|
|
|
|
|
/** @var \ReflectionParameter $param */
|
|
|
|
foreach ($params as $param) {
|
|
|
|
$param_array = $this->getReflectionParamData($param);
|
|
|
|
$storage->params[] = $param_array;
|
|
|
|
$storage->param_types[$param->name] = $param_array->type;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$storage->required_param_count = 0;
|
|
|
|
|
|
|
|
foreach ($storage->params as $i => $param) {
|
2019-03-02 21:26:18 +01:00
|
|
|
if (!$param->is_optional && !$param->is_variadic) {
|
2018-01-21 19:38:51 +01:00
|
|
|
$storage->required_param_count = $i + 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param \ReflectionParameter $param
|
|
|
|
*
|
|
|
|
* @return FunctionLikeParameter
|
|
|
|
*/
|
|
|
|
private function getReflectionParamData(\ReflectionParameter $param)
|
|
|
|
{
|
2019-01-27 23:16:22 +01:00
|
|
|
$param_type = self::getPsalmTypeFromReflectionType($param->getType());
|
|
|
|
$param_name = (string)$param->getName();
|
2018-01-21 19:38:51 +01:00
|
|
|
|
|
|
|
$is_optional = (bool)$param->isOptional();
|
|
|
|
|
2019-05-14 21:44:46 +02:00
|
|
|
$parameter = new FunctionLikeParameter(
|
2018-01-21 19:38:51 +01:00
|
|
|
$param_name,
|
|
|
|
(bool)$param->isPassedByReference(),
|
|
|
|
$param_type,
|
|
|
|
null,
|
|
|
|
null,
|
|
|
|
$is_optional,
|
2019-01-27 23:16:22 +01:00
|
|
|
$param_type->isNullable(),
|
2018-01-21 19:38:51 +01:00
|
|
|
$param->isVariadic()
|
|
|
|
);
|
2019-05-14 21:44:46 +02:00
|
|
|
|
|
|
|
$parameter->signature_type = Type::getMixed();
|
|
|
|
|
|
|
|
return $parameter;
|
2018-01-21 19:38:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-04-10 00:09:57 +02:00
|
|
|
* @param callable-string $function_id
|
2018-01-21 19:38:51 +01:00
|
|
|
*
|
|
|
|
* @return false|null
|
|
|
|
*/
|
|
|
|
public function registerFunction($function_id)
|
|
|
|
{
|
|
|
|
try {
|
|
|
|
$reflection_function = new \ReflectionFunction($function_id);
|
|
|
|
|
2019-06-15 22:10:48 +02:00
|
|
|
$callmap_callable = null;
|
2019-01-20 01:49:58 +01:00
|
|
|
|
2018-01-21 19:38:51 +01:00
|
|
|
$storage = self::$builtin_functions[$function_id] = new FunctionLikeStorage();
|
|
|
|
|
2019-01-20 01:49:58 +01:00
|
|
|
if (CallMap::inCallMap($function_id)) {
|
2019-06-15 22:10:48 +02:00
|
|
|
$callmap_callable = \Psalm\Internal\Codebase\CallMap::getCallableFromCallMapById(
|
2019-01-20 01:49:58 +01:00
|
|
|
$this->codebase,
|
|
|
|
$function_id,
|
|
|
|
[]
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-06-15 22:10:48 +02:00
|
|
|
if ($callmap_callable !== null
|
|
|
|
&& $callmap_callable->params !== null
|
|
|
|
&& $callmap_callable->return_type !== null
|
|
|
|
) {
|
|
|
|
$storage->params = $callmap_callable->params;
|
|
|
|
$storage->return_type = $callmap_callable->return_type;
|
2019-01-20 01:49:58 +01:00
|
|
|
} else {
|
|
|
|
$reflection_params = $reflection_function->getParameters();
|
|
|
|
|
|
|
|
/** @var \ReflectionParameter $param */
|
|
|
|
foreach ($reflection_params as $param) {
|
|
|
|
$param_obj = $this->getReflectionParamData($param);
|
|
|
|
$storage->params[] = $param_obj;
|
|
|
|
}
|
2019-06-15 22:10:48 +02:00
|
|
|
|
|
|
|
if ($reflection_return_type = $reflection_function->getReturnType()) {
|
|
|
|
$storage->return_type = self::getPsalmTypeFromReflectionType($reflection_return_type);
|
|
|
|
}
|
2018-01-21 19:38:51 +01:00
|
|
|
}
|
|
|
|
|
2018-03-02 05:33:21 +01:00
|
|
|
$storage->required_param_count = 0;
|
|
|
|
|
|
|
|
foreach ($storage->params as $i => $param) {
|
2019-03-02 21:26:18 +01:00
|
|
|
if (!$param->is_optional && !$param->is_variadic) {
|
2018-03-02 05:33:21 +01:00
|
|
|
$storage->required_param_count = $i + 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-21 19:38:51 +01:00
|
|
|
$storage->cased_name = $reflection_function->getName();
|
|
|
|
} catch (\ReflectionException $e) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-28 00:43:36 +01:00
|
|
|
public static function getPsalmTypeFromReflectionType(\ReflectionType $reflection_type = null) : Type\Union
|
2019-01-27 23:16:22 +01:00
|
|
|
{
|
|
|
|
if (!$reflection_type) {
|
|
|
|
return Type::getMixed();
|
|
|
|
}
|
|
|
|
|
|
|
|
$suffix = '';
|
|
|
|
|
|
|
|
if ($reflection_type->allowsNull()) {
|
|
|
|
$suffix = '|null';
|
|
|
|
}
|
|
|
|
|
2019-07-19 05:36:39 +02:00
|
|
|
return Type::parseString($reflection_type->getName() . $suffix);
|
2019-01-27 23:16:22 +01:00
|
|
|
}
|
|
|
|
|
2018-01-21 19:38:51 +01:00
|
|
|
/**
|
|
|
|
* @param string $fq_class_name
|
|
|
|
* @param string $parent_class
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
private function registerInheritedMethods(
|
|
|
|
$fq_class_name,
|
|
|
|
$parent_class
|
|
|
|
) {
|
|
|
|
$parent_storage = $this->storage_provider->get($parent_class);
|
|
|
|
$storage = $this->storage_provider->get($fq_class_name);
|
|
|
|
|
|
|
|
// register where they appear (can never be in a trait)
|
|
|
|
foreach ($parent_storage->appearing_method_ids as $method_name => $appearing_method_id) {
|
|
|
|
$storage->appearing_method_ids[$method_name] = $appearing_method_id;
|
|
|
|
}
|
|
|
|
|
|
|
|
// register where they're declared
|
|
|
|
foreach ($parent_storage->inheritable_method_ids as $method_name => $declaring_method_id) {
|
|
|
|
$storage->declaring_method_ids[$method_name] = $declaring_method_id;
|
|
|
|
$storage->inheritable_method_ids[$method_name] = $declaring_method_id;
|
|
|
|
|
2019-06-11 17:19:57 +02:00
|
|
|
$storage->overridden_method_ids[$method_name][$declaring_method_id] = $declaring_method_id;
|
2018-01-21 19:38:51 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string $fq_class_name
|
|
|
|
* @param string $parent_class
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
private function registerInheritedProperties(
|
|
|
|
$fq_class_name,
|
|
|
|
$parent_class
|
|
|
|
) {
|
|
|
|
$parent_storage = $this->storage_provider->get($parent_class);
|
|
|
|
$storage = $this->storage_provider->get($fq_class_name);
|
|
|
|
|
|
|
|
// register where they appear (can never be in a trait)
|
|
|
|
foreach ($parent_storage->appearing_property_ids as $property_name => $appearing_property_id) {
|
|
|
|
if (!$parent_storage->is_trait
|
|
|
|
&& isset($parent_storage->properties[$property_name])
|
2018-11-06 03:57:36 +01:00
|
|
|
&& $parent_storage->properties[$property_name]->visibility === ClassLikeAnalyzer::VISIBILITY_PRIVATE
|
2018-01-21 19:38:51 +01:00
|
|
|
) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
$storage->appearing_property_ids[$property_name] = $appearing_property_id;
|
|
|
|
}
|
|
|
|
|
|
|
|
// register where they're declared
|
2018-07-22 01:56:26 +02:00
|
|
|
foreach ($parent_storage->declaring_property_ids as $property_name => $declaring_property_class) {
|
2018-01-21 19:38:51 +01:00
|
|
|
if (!$parent_storage->is_trait
|
|
|
|
&& isset($parent_storage->properties[$property_name])
|
2018-11-06 03:57:36 +01:00
|
|
|
&& $parent_storage->properties[$property_name]->visibility === ClassLikeAnalyzer::VISIBILITY_PRIVATE
|
2018-01-21 19:38:51 +01:00
|
|
|
) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2018-07-22 01:56:26 +02:00
|
|
|
$storage->declaring_property_ids[$property_name] = $declaring_property_class;
|
2018-01-21 19:38:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// register where they're declared
|
|
|
|
foreach ($parent_storage->inheritable_property_ids as $property_name => $inheritable_property_id) {
|
|
|
|
if (!$parent_storage->is_trait
|
|
|
|
&& isset($parent_storage->properties[$property_name])
|
2018-11-06 03:57:36 +01:00
|
|
|
&& $parent_storage->properties[$property_name]->visibility === ClassLikeAnalyzer::VISIBILITY_PRIVATE
|
2018-01-21 19:38:51 +01:00
|
|
|
) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
$storage->inheritable_property_ids[$property_name] = $inheritable_property_id;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string $function_id
|
|
|
|
*
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function hasFunction($function_id)
|
|
|
|
{
|
|
|
|
return isset(self::$builtin_functions[$function_id]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string $function_id
|
|
|
|
*
|
|
|
|
* @return FunctionLikeStorage
|
|
|
|
*/
|
|
|
|
public function getFunctionStorage($function_id)
|
|
|
|
{
|
|
|
|
if (isset(self::$builtin_functions[$function_id])) {
|
|
|
|
return self::$builtin_functions[$function_id];
|
|
|
|
}
|
|
|
|
|
|
|
|
throw new \UnexpectedValueException('Expecting to have a function for ' . $function_id);
|
|
|
|
}
|
2019-05-17 00:36:36 +02:00
|
|
|
|
|
|
|
public static function clearCache() : void
|
|
|
|
{
|
|
|
|
self::$builtin_functions = [];
|
|
|
|
}
|
2018-01-21 19:38:51 +01:00
|
|
|
}
|