Skip to content

Commit

Permalink
Fix #1528 - double check for missing dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
muglug committed Apr 21, 2019
1 parent e08ef35 commit d68e501
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 3 deletions.
6 changes: 6 additions & 0 deletions src/Psalm/Internal/Analyzer/ClassLikeAnalyzer.php
Expand Up @@ -283,6 +283,12 @@ public static function checkFullyQualifiedClassLikeName(
}

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 '
Expand Down
10 changes: 7 additions & 3 deletions src/psalm.php
Expand Up @@ -305,8 +305,8 @@ function ($arg) use ($valid_long_options, $valid_short_options) {

$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
Expand Down Expand Up @@ -745,9 +745,13 @@ function ($arg) {
}
}

$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
);
}

Expand Down
36 changes: 36 additions & 0 deletions tests/StubTest.php
Expand Up @@ -750,6 +750,42 @@ class A {}
$this->analyzeFile($file_path, new Context());
}

/**
* @return void
*/
public function testStubFileWithExtendedStubbedClass()
{
$this->project_analyzer = $this->getProjectAnalyzerWithConfig(
TestConfig::loadFromXML(
dirname(__DIR__),
'<?xml version="1.0"?>
<psalm>
<projectFiles>
<directory name="src" />
</projectFiles>
<stubs>
<file name="tests/stubs/partial_class.php" />
</stubs>
</psalm>'
)
);

$file_path = getcwd() . '/src/somefile.php';

$this->addFile(
$file_path,
'<?php
namespace Foo;
class Bar extends PartiallyStubbedClass {}
new Bar();'
);

$this->analyzeFile($file_path, new Context());
}

/**
* @expectedException \Psalm\Exception\CodeException
* @expectedExceptionMessage TypeCoercion
Expand Down

0 comments on commit d68e501

Please sign in to comment.