1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-30 04:39:00 +01:00

Only add pure when not overriding upstream

This commit is contained in:
Brown 2020-08-23 22:16:03 -04:00
parent 6103cf0f51
commit 94cec15598
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,
],
];
}
}