From d68e501bfa016d0e58afb81f45f3793487333fba Mon Sep 17 00:00:00 2001 From: Matthew Brown Date: Sun, 21 Apr 2019 11:30:42 -0400 Subject: [PATCH] Fix #1528 - double check for missing dependency --- .../Internal/Analyzer/ClassLikeAnalyzer.php | 6 ++++ src/psalm.php | 10 ++++-- tests/StubTest.php | 36 +++++++++++++++++++ 3 files changed, 49 insertions(+), 3 deletions(-) diff --git a/src/Psalm/Internal/Analyzer/ClassLikeAnalyzer.php b/src/Psalm/Internal/Analyzer/ClassLikeAnalyzer.php index 270084f48..ceb1366c5 100644 --- a/src/Psalm/Internal/Analyzer/ClassLikeAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/ClassLikeAnalyzer.php @@ -283,6 +283,12 @@ abstract class ClassLikeAnalyzer extends SourceAnalyzer implements StatementsSou } foreach ($class_storage->invalid_dependencies as $dependency_class_name) { + // if the implemented/extended class is stubbed, it may not yet have + // been hydrated + if ($codebase->classlike_storage_provider->has($dependency_class_name)) { + continue; + } + if (IssueBuffer::accepts( new MissingDependency( $fq_class_name . ' depends on class or interface ' diff --git a/src/psalm.php b/src/psalm.php index 91f95f57d..93a92b041 100644 --- a/src/psalm.php +++ b/src/psalm.php @@ -305,8 +305,8 @@ if ($threads > 1) { $type_map_location = null; -if (isset($options['generate-type-map']) && is_string($options['generate-type-map'])) { - $type_map_location = $options['generate-type-map']; +if (isset($options['generate-json-map']) && is_string($options['generate-json-map'])) { + $type_map_location = $options['generate-json-map']; } // If XDebug is enabled, restart without it @@ -745,9 +745,13 @@ if ($type_map_location) { } } + $type_map_string = json_encode(['files' => $name_file_map, 'references' => $reference_dictionary]); + + var_dump(strlen($type_map_string)); + $providers->file_provider->setContents( $type_map_location, - json_encode(['files' => $name_file_map, 'references' => $reference_dictionary]) + $type_map_string ); } diff --git a/tests/StubTest.php b/tests/StubTest.php index 859b05090..40e6a48b0 100644 --- a/tests/StubTest.php +++ b/tests/StubTest.php @@ -750,6 +750,42 @@ class StubTest extends TestCase $this->analyzeFile($file_path, new Context()); } + /** + * @return void + */ + public function testStubFileWithExtendedStubbedClass() + { + $this->project_analyzer = $this->getProjectAnalyzerWithConfig( + TestConfig::loadFromXML( + dirname(__DIR__), + ' + + + + + + + + + ' + ) + ); + + $file_path = getcwd() . '/src/somefile.php'; + + $this->addFile( + $file_path, + 'analyzeFile($file_path, new Context()); + } + /** * @expectedException \Psalm\Exception\CodeException * @expectedExceptionMessage TypeCoercion