Skip to content

Commit

Permalink
Fix #37 - check parent calls for staticness
Browse files Browse the repository at this point in the history
  • Loading branch information
muglug committed Jan 30, 2017
1 parent a45c477 commit d978966
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Psalm/Checker/Statements/Expression/CallChecker.php
Original file line number Diff line number Diff line change
Expand Up @@ -955,7 +955,7 @@ public static function analyzeStaticCall(
}

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)
Expand Down
50 changes: 50 additions & 0 deletions tests/MethodCallTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,56 @@ public function barBar() : void {}
$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
*/
Expand Down

0 comments on commit d978966

Please sign in to comment.