From f870d761034c7a9ee7a8456f558e24ac05ffe364 Mon Sep 17 00:00:00 2001 From: Alies Lapatsin <5278175+alies-dev@users.noreply.github.com> Date: Wed, 11 Nov 2026 15:22:45 +0100 Subject: [PATCH 1/2] Mark the plugin classes final and add #[\Override] (Psalter) --- Plugin.php | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/Plugin.php b/Plugin.php index 19a1d3f..a023a23 100644 --- a/Plugin.php +++ b/Plugin.php @@ -51,7 +51,7 @@ /** * @psalm-type Hook = array{hook_type: string, types: list, deprecated: bool, minimum_invoke_args: int<0, max>} */ -class Plugin implements +final class Plugin implements AfterEveryFunctionCallAnalysisInterface, BeforeFileAnalysisInterface, FunctionParamsProviderInterface, @@ -81,6 +81,7 @@ class Plugin implements */ public static $parseErrors = []; + #[\Override] public function __invoke(RegistrationInterface $registration, ?\SimpleXMLElement $config = null): void { $registration->registerHooksFromClass(static::class); @@ -360,6 +361,7 @@ protected static function loadHooksFromFile(string $filepath): void } } + #[\Override] public static function beforeAnalyzeFile(BeforeFileAnalysisEvent $event): void { $file_path = $event->getStatementsSource()->getFilePath(); @@ -594,6 +596,7 @@ public static function getDynamicHookData(string $hook_name, bool $is_action_not return null; } + #[\Override] public static function afterEveryFunctionCallAnalysis(AfterEveryFunctionCallAnalysisEvent $event): void { $apply_filter_functions = [ @@ -732,6 +735,7 @@ public static function afterEveryFunctionCallAnalysis(AfterEveryFunctionCallAnal * * @psalm-pure */ + #[\Override] public static function getFunctionIds(): array { return [ @@ -760,6 +764,7 @@ public static function getFunctionIds(): array /** * @return ?array */ + #[\Override] public static function getFunctionParams(FunctionParamsProviderEvent $event): ?array { $function_id = $event->getFunctionId(); @@ -1082,6 +1087,7 @@ public static function getFunctionParams(FunctionParamsProviderEvent $event): ?a return $return; } + #[\Override] public static function getFunctionReturnType(FunctionReturnTypeProviderEvent $event): ?Union { if ($event->getFunctionId() === 'wp_parse_url') { @@ -1304,7 +1310,7 @@ public static function registerHook(string $hook_name, array $types, string $hoo } } -class HookNodeVisitor extends PhpParser\NodeVisitorAbstract +final class HookNodeVisitor extends PhpParser\NodeVisitorAbstract { /** @var ?PhpParser\Comment\Doc */ protected $last_doc = null; @@ -1332,6 +1338,7 @@ class HookNodeVisitor extends PhpParser\NodeVisitorAbstract */ protected $useStatementsNonClass = false; + #[\Override] public function enterNode(PhpParser\Node $node) { $apply_filter_functions = [ @@ -1663,8 +1670,8 @@ public function enterNode(PhpParser\Node $node) } } -class HookNotFound extends PluginIssue {} +final class HookNotFound extends PluginIssue {} -class HookInvalidArgs extends PluginIssue {} +final class HookInvalidArgs extends PluginIssue {} -class DeprecatedHook extends PluginIssue {} +final class DeprecatedHook extends PluginIssue {} From 089e44637916834f834ec8a5368c2f44cb677010 Mon Sep 17 00:00:00 2001 From: Alies Lapatsin <5278175+alies-dev@users.noreply.github.com> Date: Wed, 11 Nov 2026 15:22:45 +0100 Subject: [PATCH 2/2] Run Psalm on the plugin in CI, with a baseline for the existing issues --- .github/workflows/ci.yml | 36 +++++++++ psalm-baseline.xml | 154 +++++++++++++++++++++++++++++++++++++++ psalm.xml.dist | 10 +++ 3 files changed, 200 insertions(+) create mode 100644 psalm-baseline.xml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 148da62..dd0d569 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -18,6 +18,42 @@ concurrency: cancel-in-progress: true jobs: + psalm: + name: Static analysis + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v7 + + - name: Set up PHP + uses: shivammathur/setup-php@v2 + with: + php-version: '8.3' + tools: composer:v2 + coverage: none + + - name: Get Composer cache directories + id: composer-cache + run: | + echo "files_cache=$(composer config cache-files-dir)" >> "$GITHUB_OUTPUT" + echo "vcs_cache=$(composer config cache-vcs-dir)" >> "$GITHUB_OUTPUT" + + - name: Retrieve cached packages + uses: actions/cache@v6 + with: + path: | + ${{ steps.composer-cache.outputs.files_cache }} + ${{ steps.composer-cache.outputs.vcs_cache }} + key: ${{ runner.os }}-composer-${{ hashFiles('composer.json') }} + restore-keys: | + ${{ runner.os }}-composer- + + - name: Install dependencies + run: composer update --prefer-dist --prefer-stable --no-interaction --no-progress + + - name: Run Psalm + run: vendor/bin/psalm --output-format=github --shepherd + php-cs-fixer: name: Code style runs-on: ubuntu-latest diff --git a/psalm-baseline.xml b/psalm-baseline.xml new file mode 100644 index 0000000..2bed00c --- /dev/null +++ b/psalm-baseline.xml @@ -0,0 +1,154 @@ + + + + + + + + name->toString(), + true, + $context, + )]]> + + + getCodebase(), + $statements_source->node_data, + $parser_param, + $statements_source->getAliases(), + $statements_source, + )]]> + + + name->toString(), + true, + $context, + )]]> + + + getCodebase(), + $statements_source->node_data, + $parser_param, + $statements_source->getAliases(), + $statements_source, + )]]> + + + useStatements]]> + useStatements]]> + useStatements]]> + useStatements]]> + + + value]]> + + + + + + + + + node_data]]> + + + + + + + + + + + + + + name]]> + + + dim]]> + + getContext()]]> + + + + + + + + + + + name) && $call_arg->name instanceof PhpParser\Node\Identifier]]> + + + + + + + + + + + + + + + + + hooks)]]> + + alias->name)]]> + useStatements[ $class_name ])]]> + useStatements[ $node->alias->name ])]]> + alias->name)]]> + + + value->value]]> + args[ $hook_index + 1 ]->value]]> + args[ $hook_index + 1 ]->value]]> + args[ $hook_index + 1 ]->value]]> + args[ $hook_index + 1 ]->value]]> + args[ $hook_index + 1 ]->value]]> + args[ $hook_index + 1 ]->value]]> + args[ $hook_index ]->value]]> + args[ $hook_index ]->value]]> + args[0]->value]]> + args[0]->value]]> + args[0]->value]]> + args[0]->value]]> + + + + + + + + + + + + + + + + + + diff --git a/psalm.xml.dist b/psalm.xml.dist index 648df9d..d579b33 100644 --- a/psalm.xml.dist +++ b/psalm.xml.dist @@ -3,6 +3,8 @@ xmlns="https://getpsalm.org/schema/config" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd" + errorBaseline="psalm-baseline.xml" + findUnusedPsalmSuppress="true" > @@ -11,6 +13,14 @@ + + + + + + + +