mirror of
https://github.com/danog/psalm.git
synced 2024-11-30 04:39:00 +01:00
Restrict pure annotation addition a little more
This commit is contained in:
parent
0c3306b002
commit
601a8fdcb6
@ -582,6 +582,9 @@ abstract class FunctionLikeAnalyzer extends SourceAnalyzer
|
||||
if ($codebase->alter_code
|
||||
&& isset($project_analyzer->getIssuesToFix()['MissingPureAnnotation'])
|
||||
&& !$this->inferred_impure
|
||||
&& ($this->function instanceof Function_
|
||||
|| ($this->function instanceof ClassMethod
|
||||
&& $this->function->isStatic()))
|
||||
) {
|
||||
$manipulator = FunctionDocblockManipulator::getForFunction(
|
||||
$project_analyzer,
|
||||
|
@ -1226,7 +1226,8 @@ class FunctionCallAnalyzer extends CallAnalyzer
|
||||
&& ($context->mutation_free
|
||||
|| $context->external_mutation_free
|
||||
|| $codebase->find_unused_variables
|
||||
|| !$config->remember_property_assignments_after_call)
|
||||
|| !$config->remember_property_assignments_after_call
|
||||
|| $codebase->alter_code)
|
||||
) {
|
||||
$must_use = true;
|
||||
|
||||
|
@ -359,7 +359,7 @@ class FunctionDocblockManipulator
|
||||
|
||||
$old_phpdoc_return_type = null;
|
||||
if (isset($parsed_docblock->tags['return'])) {
|
||||
$old_phpdoc_return_type = array_shift($parsed_docblock->tags['return']);
|
||||
$old_phpdoc_return_type = reset($parsed_docblock->tags['return']);
|
||||
}
|
||||
|
||||
if ($this->is_pure) {
|
||||
|
@ -25,6 +25,27 @@ class PureAnnotationAdditionTest extends FileManipulationTest
|
||||
['MissingPureAnnotation'],
|
||||
true,
|
||||
],
|
||||
'addPureAnnotationToFunctionWithExistingDocblock' => [
|
||||
'<?php
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
function foo(string $s) {
|
||||
return $s;
|
||||
}',
|
||||
'<?php
|
||||
/**
|
||||
* @return string
|
||||
*
|
||||
* @psalm-pure
|
||||
*/
|
||||
function foo(string $s) {
|
||||
return $s;
|
||||
}',
|
||||
'7.4',
|
||||
['MissingPureAnnotation'],
|
||||
true,
|
||||
],
|
||||
'dontAddPureAnnotationToImpureFunction' => [
|
||||
'<?php
|
||||
function foo(string $s): string {
|
||||
@ -61,6 +82,25 @@ class PureAnnotationAdditionTest extends FileManipulationTest
|
||||
['MissingPureAnnotation'],
|
||||
true,
|
||||
],
|
||||
'dontAddPureAnnotationToFunctionWithImpureCall' => [
|
||||
'<?php
|
||||
function foo(string $s): string {
|
||||
if (file_exists($s)) {
|
||||
return "";
|
||||
}
|
||||
return $s;
|
||||
}',
|
||||
'<?php
|
||||
function foo(string $s): string {
|
||||
if (file_exists($s)) {
|
||||
return "";
|
||||
}
|
||||
return $s;
|
||||
}',
|
||||
'7.4',
|
||||
['MissingPureAnnotation'],
|
||||
true,
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user