1
0
mirror of https://github.com/danog/psalm.git synced 2025-01-21 21:31:13 +01:00

Fix #37 - check parent calls for staticness

This commit is contained in:
Matthew Brown 2017-01-29 22:13:53 -05:00
parent a45c47776b
commit d978966db4
2 changed files with 51 additions and 1 deletions

View File

@ -955,7 +955,7 @@ class CallChecker
}
if ($stmt->class instanceof PhpParser\Node\Name
&& $stmt->class->parts[0] !== 'parent'
&& ($stmt->class->parts[0] !== 'parent' || $statements_checker->isStatic())
&& (!$context->self
|| $statements_checker->isStatic()
|| !ClassChecker::classExtends($context->self, $fq_class_name)

View File

@ -53,6 +53,56 @@ class MethodCallTest extends PHPUnit_Framework_TestCase
$file_checker->visitAndAnalyzeMethods($context);
}
/**
* @expectedException \Psalm\Exception\CodeException
* @expectedExceptionMessage InvalidStaticInvocation
* @return void
*/
public function testInvalidParentStaticCall()
{
$stmts = self::$parser->parse('<?php
class A {
/** @return void */
public function foo(){}
}
class B extends A {
/** @return void */
public static function bar(){
parent::foo();
}
}
');
$file_checker = new FileChecker('somefile.php', $this->project_checker, $stmts);
$context = new Context();
$file_checker->visitAndAnalyzeMethods($context);
}
/**
* @return void
*/
public function testValidParentStaticCall()
{
$stmts = self::$parser->parse('<?php
class A {
/** @return void */
public static function foo(){}
}
class B extends A {
/** @return void */
public static function bar(){
parent::foo();
}
}
');
$file_checker = new FileChecker('somefile.php', $this->project_checker, $stmts);
$context = new Context();
$file_checker->visitAndAnalyzeMethods($context);
}
/**
* @return void
*/