From d3f8e80c4abfd559e31e537159b2385fab4f7f51 Mon Sep 17 00:00:00 2001 From: Matthew Brown Date: Sun, 23 Feb 2020 14:53:31 -0500 Subject: [PATCH] Move reference map generation into separate file --- .../Codebase/ReferenceMapGenerator.php | 55 +++++++++++++++++++ src/psalm.php | 46 ++-------------- 2 files changed, 59 insertions(+), 42 deletions(-) create mode 100644 src/Psalm/Internal/Codebase/ReferenceMapGenerator.php diff --git a/src/Psalm/Internal/Codebase/ReferenceMapGenerator.php b/src/Psalm/Internal/Codebase/ReferenceMapGenerator.php new file mode 100644 index 000000000..573fc9b9e --- /dev/null +++ b/src/Psalm/Internal/Codebase/ReferenceMapGenerator.php @@ -0,0 +1,55 @@ +getAll() as $storage) { + if (!$storage->location) { + continue; + } + + $fq_classlike_name = $storage->name; + + if (isset($expected_references[$fq_classlike_name])) { + $reference_dictionary[$fq_classlike_name] + = $storage->location->file_name + . ':' . $storage->location->getLineNumber() + . ':' . $storage->location->getColumn(); + } + + foreach ($storage->methods as $method_name => $method_storage) { + if (!$method_storage->location) { + continue; + } + + if (isset($expected_references[$fq_classlike_name . '::' . $method_name . '()'])) { + $reference_dictionary[$fq_classlike_name . '::' . $method_name . '()'] + = $method_storage->location->file_name + . ':' . $method_storage->location->getLineNumber() + . ':' . $method_storage->location->getColumn(); + } + } + + foreach ($storage->properties as $property_name => $property_storage) { + if (!$property_storage->location) { + continue; + } + + if (isset($expected_references[$fq_classlike_name . '::$' . $property_name])) { + $reference_dictionary[$fq_classlike_name . '::$' . $property_name] + = $property_storage->location->file_name + . ':' . $property_storage->location->getLineNumber() + . ':' . $property_storage->location->getColumn(); + } + } + } + + return $reference_dictionary; + } +} diff --git a/src/psalm.php b/src/psalm.php index 46677c61b..fd6b9aff3 100644 --- a/src/psalm.php +++ b/src/psalm.php @@ -693,48 +693,10 @@ if ($type_map_location) { $name_file_map[$file_name] = $map; } - $reference_dictionary = []; - - foreach ($providers->classlike_storage_provider->getAll() as $storage) { - if (!$storage->location) { - continue; - } - - $fq_classlike_name = $storage->name; - - if (isset($expected_references[$fq_classlike_name])) { - $reference_dictionary[$fq_classlike_name] - = $storage->location->file_name - . ':' . $storage->location->getLineNumber() - . ':' . $storage->location->getColumn(); - } - - foreach ($storage->methods as $method_name => $method_storage) { - if (!$method_storage->location) { - continue; - } - - if (isset($expected_references[$fq_classlike_name . '::' . $method_name . '()'])) { - $reference_dictionary[$fq_classlike_name . '::' . $method_name . '()'] - = $method_storage->location->file_name - . ':' . $method_storage->location->getLineNumber() - . ':' . $method_storage->location->getColumn(); - } - } - - foreach ($storage->properties as $property_name => $property_storage) { - if (!$property_storage->location) { - continue; - } - - if (isset($expected_references[$fq_classlike_name . '::$' . $property_name])) { - $reference_dictionary[$fq_classlike_name . '::$' . $property_name] - = $property_storage->location->file_name - . ':' . $property_storage->location->getLineNumber() - . ':' . $property_storage->location->getColumn(); - } - } - } + $reference_dictionary = \Psalm\Internal\Codebase\ReferenceMapGenerator::getReferenceMap( + $providers->classlike_storage_provider, + $expected_references + ); $type_map_string = json_encode(['files' => $name_file_map, 'references' => $reference_dictionary]);