1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-27 04:45:20 +01:00

Break up Populator method

This commit is contained in:
Matthew Brown 2018-02-03 20:03:31 -05:00
parent 8e0998e081
commit 77a0720b65
2 changed files with 93 additions and 51 deletions

View File

@ -479,8 +479,6 @@ abstract class ClassLikeChecker extends SourceChecker implements StatementsSourc
{
$class_name = strtolower($class_name);
$class_name = strtolower($class_name);
$storage = $project_checker->classlike_storage_provider->get($class_name);
if ($visibility === ReflectionProperty::IS_PUBLIC) {

View File

@ -141,7 +141,7 @@ class Populator
*
* @return void
*/
private function populateClassLikeStorage(ClassLikeStorage $storage, $dependent_classlikes = [])
private function populateClassLikeStorage(ClassLikeStorage $storage, array $dependent_classlikes = [])
{
if ($storage->populated) {
return;
@ -164,6 +164,53 @@ class Populator
$storage_provider = $this->classlike_storage_provider;
$this->populateDataFromTraits($storage, $storage_provider, $dependent_classlikes);
$dependent_classlikes[$fq_classlike_name_lc] = true;
if ($storage->parent_classes) {
$this->populateDataFromParentClass($storage, $storage_provider, $dependent_classlikes);
}
$this->populateInterfaceDataFromParentInterfaces($storage, $storage_provider, $dependent_classlikes);
$this->populateDataFromImplementedInterfaces($storage, $storage_provider, $dependent_classlikes);
if ($storage->location) {
$file_path = $storage->location->file_path;
foreach ($storage->parent_interfaces as $parent_interface_lc) {
FileReferenceProvider::addFileInheritanceToClass($file_path, $parent_interface_lc);
}
foreach ($storage->parent_classes as $parent_class_lc) {
FileReferenceProvider::addFileInheritanceToClass($file_path, $parent_class_lc);
}
foreach ($storage->class_implements as $implemented_interface) {
FileReferenceProvider::addFileInheritanceToClass($file_path, strtolower($implemented_interface));
}
foreach ($storage->used_traits as $used_trait_lc) {
FileReferenceProvider::addFileInheritanceToClass($file_path, $used_trait_lc);
}
}
if ($this->debug_output) {
echo 'Have populated ' . $storage->name . PHP_EOL;
}
$storage->populated = true;
}
/**
* @return void
*/
private function populateDataFromTraits(
ClassLikeStorage $storage,
ClassLikeStorageProvider $storage_provider,
array $dependent_classlikes
) {
foreach ($storage->used_traits as $used_trait_lc => $_) {
try {
$trait_storage = $storage_provider->get($used_trait_lc);
@ -176,10 +223,16 @@ class Populator
$this->inheritMethodsFromParent($storage, $trait_storage);
$this->inheritPropertiesFromParent($storage, $trait_storage);
}
}
$dependent_classlikes[$fq_classlike_name_lc] = true;
if ($storage->parent_classes) {
/**
* @return void
*/
private function populateDataFromParentClass(
ClassLikeStorage $storage,
ClassLikeStorageProvider $storage_provider,
array $dependent_classlikes
) {
try {
$parent_storage = $storage_provider->get(reset($storage->parent_classes));
} catch (\InvalidArgumentException $e) {
@ -201,6 +254,14 @@ class Populator
}
}
/**
* @return void
*/
private function populateInterfaceDataFromParentInterfaces(
ClassLikeStorage $storage,
ClassLikeStorageProvider $storage_provider,
array $dependent_classlikes
) {
$parent_interfaces = [];
foreach ($storage->parent_interfaces as $parent_interface_lc => $_) {
@ -224,7 +285,16 @@ class Populator
}
$storage->parent_interfaces = array_merge($parent_interfaces, $storage->parent_interfaces);
}
/**
* @return void
*/
private function populateDataFromImplementedInterfaces(
ClassLikeStorage $storage,
ClassLikeStorageProvider $storage_provider,
array $dependent_classlikes
) {
$extra_interfaces = [];
foreach ($storage->class_implements as $implemented_interface_lc => $_) {
@ -276,32 +346,6 @@ class Populator
$storage->interface_method_ids[$method_name] = $interface_method_ids;
}
}
if ($storage->location) {
$file_path = $storage->location->file_path;
foreach ($storage->parent_interfaces as $parent_interface_lc) {
FileReferenceProvider::addFileInheritanceToClass($file_path, $parent_interface_lc);
}
foreach ($storage->parent_classes as $parent_class_lc) {
FileReferenceProvider::addFileInheritanceToClass($file_path, $parent_class_lc);
}
foreach ($storage->class_implements as $implemented_interface) {
FileReferenceProvider::addFileInheritanceToClass($file_path, strtolower($implemented_interface));
}
foreach ($storage->used_traits as $used_trait_lc) {
FileReferenceProvider::addFileInheritanceToClass($file_path, $used_trait_lc);
}
}
if ($this->debug_output) {
echo 'Have populated ' . $storage->name . PHP_EOL;
}
$storage->populated = true;
}
/**