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

Only add pure to functions with params

This commit is contained in:
Brown 2020-08-23 18:41:31 -04:00 committed by Daniil Gentili
parent 9100c26439
commit 1ec0f35011
Signed by: danog
GPG Key ID: 8C1BE3B34B230CA7
3 changed files with 36 additions and 0 deletions

View File

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

View File

@ -0,0 +1,8 @@
<?php
namespace Psalm\Issue;
class ImpureVariable extends CodeIssue
{
const ERROR_LEVEL = -1;
const SHORTCODE = 235;
}

View File

@ -116,6 +116,33 @@ class PureAnnotationAdditionTest extends FileManipulationTest
['MissingPureAnnotation'],
true,
],
'dontAddWhenReferencingThis' => [
'<?php
class A {
public int $a = 5;
/**
* @psalm-pure
*/
public function foo() : self {
return $this;
}
}',
'<?php
class A {
public int $a = 5;
/**
* @psalm-pure
*/
public function foo() : self {
return $this;
}
}',
'7.4',
['MissingPureAnnotation'],
true,
],
];
}
}