1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-30 04:39:00 +01:00

Treat reflected interface parents correctly

This commit is contained in:
Matthew Brown 2017-01-16 20:47:23 -05:00
parent 0c40785660
commit b9bad01dbd
2 changed files with 32 additions and 3 deletions

View File

@ -247,8 +247,6 @@ abstract class ClassLikeChecker extends SourceChecker implements StatementsSourc
$extra_interfaces = array_unique($extra_interfaces);
//var_dump(self::$storage);
foreach ($extra_interfaces as $extra_interface_name) {
FileChecker::addFileInheritanceToClass($long_file_name, $extra_interface_name);
@ -1163,7 +1161,12 @@ abstract class ClassLikeChecker extends SourceChecker implements StatementsSourc
foreach ($interfaces as $interface) {
$interface_name = $interface->getName();
self::registerReflectedClass($interface_name, $interface, $project_checker);
$storage->class_implements[strtolower($interface_name)] = $interface_name;
if ($reflected_class->isInterface()) {
$storage->parent_interfaces[] = $interface_name;
} else {
$storage->class_implements[strtolower($interface_name)] = $interface_name;
}
}
/** @var \ReflectionMethod $reflection_method */

View File

@ -423,4 +423,30 @@ class Php71Test extends PHPUnit_Framework_TestCase
$context = new Context();
$file_checker->visitAndAnalyzeMethods($context);
}
/**
* @return void
*/
public function testTraversableObject()
{
$stmts = self::$parser->parse('<?php
class IteratorObj implements Iterator {
function rewind() : void {}
/** @return mixed */
function current() { return null; }
function key() : int { return 0; }
function next() : void {}
function valid() : bool { return false; }
}
function foo(\Traversable $t) : void {
}
foo(new IteratorObj);
');
$file_checker = new FileChecker('somefile.php', $this->project_checker, $stmts);
$context = new Context();
$file_checker->visitAndAnalyzeMethods($context);
}
}