mirror of
https://github.com/danog/psalm.git
synced 2024-11-30 04:39:00 +01:00
Migrate class constant handling into codebase classes
This commit is contained in:
parent
6f7903716d
commit
283e0a6af2
@ -17,7 +17,6 @@ use Psalm\Provider\FileReferenceProvider;
|
||||
use Psalm\StatementsSource;
|
||||
use Psalm\Storage\ClassLikeStorage;
|
||||
use Psalm\Type;
|
||||
use ReflectionProperty;
|
||||
|
||||
abstract class ClassLikeChecker extends SourceChecker implements StatementsSource
|
||||
{
|
||||
@ -430,40 +429,6 @@ abstract class ClassLikeChecker extends SourceChecker implements StatementsSourc
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $class_name
|
||||
* @param mixed $visibility
|
||||
*
|
||||
* @return array<string,Type\Union>
|
||||
*/
|
||||
public static function getConstantsForClass(ProjectChecker $project_checker, $class_name, $visibility)
|
||||
{
|
||||
$class_name = strtolower($class_name);
|
||||
|
||||
$storage = $project_checker->classlike_storage_provider->get($class_name);
|
||||
|
||||
if ($visibility === ReflectionProperty::IS_PUBLIC) {
|
||||
return $storage->public_class_constants;
|
||||
}
|
||||
|
||||
if ($visibility === ReflectionProperty::IS_PROTECTED) {
|
||||
return array_merge(
|
||||
$storage->public_class_constants,
|
||||
$storage->protected_class_constants
|
||||
);
|
||||
}
|
||||
|
||||
if ($visibility === ReflectionProperty::IS_PRIVATE) {
|
||||
return array_merge(
|
||||
$storage->public_class_constants,
|
||||
$storage->protected_class_constants,
|
||||
$storage->private_class_constants
|
||||
);
|
||||
}
|
||||
|
||||
throw new \InvalidArgumentException('Must specify $visibility');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $property_id
|
||||
* @param string|null $calling_context
|
||||
|
@ -161,8 +161,7 @@ class ConstFetchChecker
|
||||
$class_visibility = \ReflectionProperty::IS_PUBLIC;
|
||||
}
|
||||
|
||||
$class_constants = ClassLikeChecker::getConstantsForClass(
|
||||
$project_checker,
|
||||
$class_constants = $codebase->classlikes->getConstantsForClass(
|
||||
$fq_class_name,
|
||||
$class_visibility
|
||||
);
|
||||
@ -171,8 +170,7 @@ class ConstFetchChecker
|
||||
$all_class_constants = [];
|
||||
|
||||
if ($fq_class_name !== $context->self) {
|
||||
$all_class_constants = ClassLikeChecker::getConstantsForClass(
|
||||
$project_checker,
|
||||
$all_class_constants = $codebase->classlikes->getConstantsForClass(
|
||||
$fq_class_name,
|
||||
\ReflectionProperty::IS_PRIVATE
|
||||
);
|
||||
|
@ -617,6 +617,40 @@ class ClassLikes
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $class_name
|
||||
* @param mixed $visibility
|
||||
*
|
||||
* @return array<string,Type\Union>
|
||||
*/
|
||||
public function getConstantsForClass($class_name, $visibility)
|
||||
{
|
||||
$class_name = strtolower($class_name);
|
||||
|
||||
$storage = $this->classlike_storage_provider->get($class_name);
|
||||
|
||||
if ($visibility === ReflectionProperty::IS_PUBLIC) {
|
||||
return $storage->public_class_constants;
|
||||
}
|
||||
|
||||
if ($visibility === ReflectionProperty::IS_PROTECTED) {
|
||||
return array_merge(
|
||||
$storage->public_class_constants,
|
||||
$storage->protected_class_constants
|
||||
);
|
||||
}
|
||||
|
||||
if ($visibility === ReflectionProperty::IS_PRIVATE) {
|
||||
return array_merge(
|
||||
$storage->public_class_constants,
|
||||
$storage->protected_class_constants,
|
||||
$storage->private_class_constants
|
||||
);
|
||||
}
|
||||
|
||||
throw new \InvalidArgumentException('Must specify $visibility');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $class_name
|
||||
* @param string $const_name
|
||||
|
Loading…
Reference in New Issue
Block a user