From e300550209c787e0aad04027dcee2eef788d0865 Mon Sep 17 00:00:00 2001 From: Matt Brown Date: Thu, 12 Jan 2017 11:16:00 -0500 Subject: [PATCH] Be less brittle when interface does not exist --- src/Psalm/Checker/ClassLikeChecker.php | 4 ++++ tests/InterfaceTest.php | 17 +++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/src/Psalm/Checker/ClassLikeChecker.php b/src/Psalm/Checker/ClassLikeChecker.php index c3b637b28..842239a57 100644 --- a/src/Psalm/Checker/ClassLikeChecker.php +++ b/src/Psalm/Checker/ClassLikeChecker.php @@ -329,6 +329,10 @@ abstract class ClassLikeChecker extends SourceChecker implements StatementsSourc $class_interfaces = ClassChecker::getInterfacesForClass($this->fq_class_name); foreach ($class_interfaces as $interface_id => $interface_name) { + if (!isset(self::$storage[strtolower($interface_name)])) { + continue; + } + $interface_storage = self::$storage[strtolower($interface_name)]; $storage->public_class_constants += $interface_storage->public_class_constants; diff --git a/tests/InterfaceTest.php b/tests/InterfaceTest.php index 922aa3247..874c71553 100644 --- a/tests/InterfaceTest.php +++ b/tests/InterfaceTest.php @@ -365,4 +365,21 @@ class InterfaceTest extends PHPUnit_Framework_TestCase $context = new Context('somefile.php'); $file_checker->visitAndAnalyzeMethods($context); } + + /** + * @expectedException \Psalm\Exception\CodeException + * @expectedExceptionMessage UndefinedClass + */ + public function testInvalidImplements() + { + $this->project_checker->registerFile( + getcwd() . '/somefile.php', + 'project_checker); + $context = new Context('somefile.php'); + $file_checker->visitAndAnalyzeMethods($context); + } }