Skip to content
Permalink
Browse files

Add support for @psalm-mutation-free annotation on methods

  • Loading branch information...
muglug committed Aug 31, 2019
1 parent 504ccda commit 7886d5a40801af18aff9db447498f8d4fb9e34fd
Showing with 28 additions and 0 deletions.
  1. +9 −0 src/Psalm/Internal/Analyzer/CommentAnalyzer.php
  2. +19 −0 tests/UnusedCodeTest.php
@@ -666,6 +666,15 @@ public static function extractFunctionDocblockInfo(PhpParser\Comment\Doc $commen
$info->variadic = isset($parsed_docblock['specials']['psalm-variadic']);
$info->pure = isset($parsed_docblock['specials']['psalm-pure'])
|| isset($parsed_docblock['specials']['pure']);
if (isset($parsed_docblock['specials']['psalm-mutation-free'])) {
$info->mutation_free = true;
}
if (isset($parsed_docblock['specials']['psalm-external-mutation-free'])) {
$info->external_mutation_free = true;
}
$info->ignore_nullable_return = isset($parsed_docblock['specials']['psalm-ignore-nullable-return']);
$info->ignore_falsable_return = isset($parsed_docblock['specials']['psalm-ignore-falsable-return']);
@@ -830,6 +830,25 @@ function foo() : void {
}',
'error_message' => 'UnusedMethodCall',
],
'annotatedMutationFreeUnused' => [
'<?php
class A {
private string $s;
public function __construct(string $s) {
$this->s = $s;
}
/** @psalm-mutation-free */
public function getShort() : string {
return substr($this->s, 0, 5);
}
}
$a = new A("hello");
$a->getShort();',
'error_message' => 'UnusedMethodCall',
]
];
}
}

0 comments on commit 7886d5a

Please sign in to comment.
You can’t perform that action at this time.