1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-26 20:34:47 +01:00

Be more resilient if we ignore that parent class does not exist

This commit is contained in:
Matthew Brown 2017-01-23 13:21:40 -07:00
parent 374dc65de1
commit 3ad6ec2e34
2 changed files with 41 additions and 2 deletions

View File

@ -603,6 +603,11 @@ abstract class ClassLikeChecker extends SourceChecker implements StatementsSourc
return false;
}
// if we don't care the parent class does not exist, exit now.
if (!ClassLikeChecker::classOrInterfaceExists($parent_class, $this->getFileChecker())) {
return;
}
self::$class_extends[$this->fq_class_name] = self::$class_extends[$this->parent_fq_class_name];
self::$class_extends[$this->fq_class_name][$this->parent_fq_class_name] = true;

View File

@ -21,8 +21,6 @@ class ClassTest extends PHPUnit_Framework_TestCase
public static function setUpBeforeClass()
{
self::$parser = (new ParserFactory)->create(ParserFactory::PREFER_PHP7);
$config = new TestConfig();
}
/**
@ -30,6 +28,7 @@ class ClassTest extends PHPUnit_Framework_TestCase
*/
public function setUp()
{
$config = new TestConfig();
FileChecker::clearCache();
$this->project_checker = new \Psalm\Checker\ProjectChecker();
}
@ -532,4 +531,39 @@ class ClassTest extends PHPUnit_Framework_TestCase
$context = new Context();
$file_checker->visitAndAnalyzeMethods($context);
}
/**
* @expectedException \Psalm\Exception\CodeException
* @expectedExceptionMessage UndefinedClass
* @return void
*/
public function testMissingParent()
{
$stmts = self::$parser->parse('<?php
class A extends B { }
');
$file_checker = new FileChecker('somefile.php', $this->project_checker, $stmts);
$context = new Context();
$file_checker->visitAndAnalyzeMethods($context);
}
/**
* @return void
*/
public function testMissingParentWithFunction()
{
Config::getInstance()->setCustomErrorLevel('UndefinedClass', Config::REPORT_SUPPRESS);
$stmts = self::$parser->parse('<?php
class A extends B {
/** @return void */
public function foo() { }
}
');
$file_checker = new FileChecker('somefile.php', $this->project_checker, $stmts);
$context = new Context();
$file_checker->visitAndAnalyzeMethods($context);
}
}