1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-26 20:34:47 +01:00

Only add pure when not overriding upstream

This commit is contained in:
Brown 2020-08-23 22:16:03 -04:00 committed by Daniil Gentili
parent fe5fd82a93
commit 596492a95a
Signed by: danog
GPG Key ID: 8C1BE3B34B230CA7
2 changed files with 70 additions and 0 deletions

View File

@ -585,6 +585,7 @@ abstract class FunctionLikeAnalyzer extends SourceAnalyzer
&& ($this->function instanceof Function_
|| $this->function instanceof ClassMethod)
&& $storage->params
&& !$overridden_method_ids
) {
$manipulator = FunctionDocblockManipulator::getForFunction(
$project_analyzer,

View File

@ -141,6 +141,75 @@ class PureAnnotationAdditionTest extends FileManipulationTest
['MissingPureAnnotation'],
true,
],
'dontAddInChildMethod' => [
'<?php
class A {
public int $a = 5;
public function foo(string $s) : string {
return $string . $this->a;
}
}
class B extends A {
public function foo(string $s) : string {
return $string;
}
}',
'<?php
class A {
public int $a = 5;
public function foo(string $s) : string {
return $string . $this->a;
}
}
class B extends A {
public function foo(string $s) : string {
return $string;
}
}',
'7.4',
['MissingPureAnnotation'],
true,
],
'doAddInOtherMethod' => [
'<?php
class A {
public int $a = 5;
public function foo(string $s) : string {
return $string . $this->a;
}
}
class B extends A {
public function bar(string $s) : string {
return $string;
}
}',
'<?php
class A {
public int $a = 5;
public function foo(string $s) : string {
return $string . $this->a;
}
}
class B extends A {
/**
* @psalm-pure
*/
public function bar(string $s) : string {
return $string;
}
}',
'7.4',
['MissingPureAnnotation'],
true,
],
];
}
}