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

Support a bunch of attributes

This commit is contained in:
Matt Brown 2020-10-30 21:38:27 -04:00 committed by Daniil Gentili
parent b217916f37
commit 15059aa50a
Signed by: danog
GPG Key ID: 8C1BE3B34B230CA7
2 changed files with 75 additions and 3 deletions

View File

@ -692,7 +692,7 @@ class ClassLikeNodeScanner
foreach ($node->attrGroups as $attr_group) {
foreach ($attr_group->attrs as $attr) {
$storage->attributes[] = AttributeResolver::resolve(
$attribute = AttributeResolver::resolve(
$this->codebase,
$this->file_scanner,
$this->file_storage,
@ -700,6 +700,29 @@ class ClassLikeNodeScanner
$attr,
$this->storage->name ?? null
);
if ($attribute->fq_class_name === 'Psalm\\Deprecated'
|| $attribute->fq_class_name === 'JetBrains\\PhpStorm\\Deprecated'
) {
$storage->deprecated = true;
}
if ($attribute->fq_class_name === 'Psalm\\Internal' && !$storage->internal) {
$storage->internal = NamespaceAnalyzer::getNameSpaceRoot($fq_classlike_name);
}
if ($attribute->fq_class_name === 'Psalm\\Immutable'
|| $attribute->fq_class_name === 'JetBrains\\PhpStorm\\Immutable'
) {
$storage->mutation_free = true;
$storage->external_mutation_free = true;
}
if ($attribute->fq_class_name === 'Psalm\\ExternalMutationFree') {
$storage->external_mutation_free = true;
}
$storage->attributes[] = $attribute;
}
}
@ -1416,7 +1439,7 @@ class ClassLikeNodeScanner
foreach ($stmt->attrGroups as $attr_group) {
foreach ($attr_group->attrs as $attr) {
$property_storage->attributes[] = AttributeResolver::resolve(
$attribute = AttributeResolver::resolve(
$this->codebase,
$this->file_scanner,
$this->file_storage,
@ -1424,6 +1447,22 @@ class ClassLikeNodeScanner
$attr,
$this->storage->name ?? null
);
if ($attribute->fq_class_name === 'Psalm\\Deprecated'
|| $attribute->fq_class_name === 'JetBrains\\PhpStorm\\Deprecated'
) {
$property_storage->deprecated = true;
}
if ($attribute->fq_class_name === 'Psalm\\Internal' && !$property_storage->internal) {
$property_storage->internal = NamespaceAnalyzer::getNameSpaceRoot($fq_classlike_name);
}
if ($attribute->fq_class_name === 'Psalm\\Readonly') {
$property_storage->readonly = true;
}
$property_storage->attributes[] = $attribute;
}
}
}

View File

@ -15,6 +15,7 @@ use Psalm\Exception\DocblockParseException;
use Psalm\Exception\IncorrectDocblockException;
use Psalm\Internal\Analyzer\ClassLikeAnalyzer;
use Psalm\Internal\Analyzer\CommentAnalyzer;
use Psalm\Internal\Analyzer\NamespaceAnalyzer;
use Psalm\Internal\Analyzer\Statements\Expression\SimpleTypeInferer;
use Psalm\Internal\Scanner\FileScanner;
use Psalm\Internal\Type\TypeAlias;
@ -768,7 +769,7 @@ class FunctionLikeNodeScanner
foreach ($stmt->getAttrGroups() as $attr_group) {
foreach ($attr_group->attrs as $attr) {
$storage->attributes[] = AttributeResolver::resolve(
$attribute = AttributeResolver::resolve(
$this->codebase,
$this->file_scanner,
$this->file_storage,
@ -776,6 +777,38 @@ class FunctionLikeNodeScanner
$attr,
$this->classlike_storage->name ?? null
);
if ($attribute->fq_class_name === 'Psalm\\Pure'
|| $attribute->fq_class_name === 'JetBrains\\PhpStorm\\Pure'
) {
$storage->specialize_call = true;
$storage->mutation_free = true;
if ($storage instanceof MethodStorage) {
$storage->external_mutation_free = true;
}
}
if ($attribute->fq_class_name === 'Psalm\\Deprecated'
|| $attribute->fq_class_name === 'JetBrains\\PhpStorm\\Deprecated'
) {
$storage->deprecated = true;
}
if ($attribute->fq_class_name === 'Psalm\\Internal' && !$storage->internal && $fq_classlike_name) {
$storage->internal = NamespaceAnalyzer::getNameSpaceRoot($fq_classlike_name);
}
if ($attribute->fq_class_name === 'Psalm\\ExternalMutationFree'
&& $storage instanceof MethodStorage
) {
$storage->external_mutation_free = true;
}
if ($attribute->fq_class_name === 'JetBrains\\PhpStorm\\NoReturn') {
$storage->return_type = new Type\Union([new Type\Atomic\TNever()]);
}
$storage->attributes[] = $attribute;
}
}