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:
parent
a45c47776b
commit
d978966db4
@ -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)
|
||||
|
@ -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
|
||||
*/
|
||||
|
Loading…
x
Reference in New Issue
Block a user