Skip to content

Commit

Permalink
Merge pull request #9383 from weirdan/process-psalm-api-on-methods
Browse files Browse the repository at this point in the history
  • Loading branch information
weirdan committed Feb 23, 2023
2 parents d0a1400 + 2e90cb6 commit e96a929
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Psalm/Internal/Codebase/ClassLikes.php
Expand Up @@ -1703,6 +1703,10 @@ private function checkMethodReferences(ClassLikeStorage $classlike_storage, Meth
continue;
}

if ($method_storage->public_api) {
continue;
}

if ($method_storage->location
&& !$project_analyzer->canReportIssues($method_storage->location->file_path)
&& !$codebase->analyzer->canReportIssues($method_storage->location->file_path)
Expand Down
Expand Up @@ -555,6 +555,8 @@ public static function parse(
$info->description = $parsed_docblock->description;
}

$info->public_api = isset($parsed_docblock->tags['psalm-api']) || isset($parsed_docblock->tags['api']);

return $info;
}

Expand Down
Expand Up @@ -417,6 +417,8 @@ public static function addDocblockInfo(
if ($docblock_info->description) {
$storage->description = $docblock_info->description;
}

$storage->public_api = $docblock_info->public_api;
}

/**
Expand Down
2 changes: 2 additions & 0 deletions src/Psalm/Internal/Scanner/FunctionDocblockComment.php
Expand Up @@ -174,4 +174,6 @@ class FunctionDocblockComment

/** @var array<string, array{lines:list<int>, suggested_replacement?:string}> */
public array $unexpected_tags = [];

public bool $public_api = false;
}
2 changes: 2 additions & 0 deletions src/Psalm/Storage/FunctionLikeStorage.php
Expand Up @@ -243,6 +243,8 @@ abstract class FunctionLikeStorage implements HasAttributesInterface
*/
public $description;

public bool $public_api = false;

public function __toString(): string
{
return $this->getSignature(false);
Expand Down
10 changes: 10 additions & 0 deletions tests/UnusedCodeTest.php
Expand Up @@ -1263,6 +1263,16 @@ protected function c(): void {}
}
PHP,
],
'psalm-api on unused public method' => [
'code' => <<<'PHP'
<?php
class A {
/** @psalm-api */
public function b(): void {}
}
new A;
PHP,
],
];
}

Expand Down

0 comments on commit e96a929

Please sign in to comment.