Skip to content

Commit

Permalink
Fix #2095 - respect @method annotations even when method already exists
Browse files Browse the repository at this point in the history
  • Loading branch information
muglug committed Sep 4, 2019
1 parent de5df1e commit 071fae9
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
Expand Up @@ -840,7 +840,10 @@ function (PhpParser\Node\Arg $arg) {
$method_id,
$context->calling_method_id,
$method_id !== $source_method_id ? new CodeLocation($source, $stmt->name) : null
)) {
)
|| ($config->use_phpdoc_method_without_magic_or_parent
&& isset($class_storage->pseudo_methods[$method_name_lc]))
) {
$class_storage = $codebase->classlike_storage_provider->get($fq_class_name);

if (($is_interface || $config->use_phpdoc_method_without_magic_or_parent)
Expand Down
22 changes: 22 additions & 0 deletions tests/MagicMethodAnnotationTest.php
Expand Up @@ -131,6 +131,28 @@ class Child extends ParentClass {}
$this->assertSame('Child', (string) $context->vars_in_scope['$child']);
}

public function testOverrideExceptionMethodReturn() : void
{
Config::getInstance()->use_phpdoc_method_without_magic_or_parent = true;

$this->addFile(
'somefile.php',
'<?php
/**
* @method int getCode()
*/
class MyException extends Exception {}
function foo(MyException $e): int {
return $e->getCode();
}'
);

$context = new Context();

$this->analyzeFile('somefile.php', $context);
}

/**
* @return iterable<string,array{string,assertions?:array<string,string>,error_levels?:string[]}>
*/
Expand Down

0 comments on commit 071fae9

Please sign in to comment.