Skip to content

fix(docblock): @implements naming another interface reports the same message with or without type arguments - #14650

Merged
orklah merged 2 commits into
vimeo:masterfrom
jirkace:fix/6096-template-implements-messages
Nov 23, 2026
Merged

orklah merged 2 commits into
vimeo:masterfrom
jirkace:fix/6096-template-implements-messages

Conversation

@jirkace

@jirkace jirkace commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

@implements naming an interface the class doesn't implement reports a misleading has invalid class when the interface has no type arguments, and the message for the generic case calls the interface a class (@use: "an used class").

Before

<?php
interface I {}

interface J {}

/** @implements J */ // InvalidDocblock: @template-implements has invalid class J
final class C implements I {}

After

/** @implements J */ // InvalidDocblock: @template-implements must include the name of an implemented interface, got J

Fixes #6096

…message with or without type arguments vimeo#6096

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@jirkace

jirkace commented Nov 22, 2026

Copy link
Copy Markdown
Contributor Author

Behaviour change (messages only; the issue type and location stay InvalidDocblock on the tag)

  • @extends / @implements / @use naming a class-like the class doesn't extend, implement or use now reports ... must include the name of ... whether or not type arguments are given. Before, without type arguments it reported ... has invalid class X.
  • Wording: an implemented class → an implemented interface, an used class → a used trait. The existing tests implementsTagNamingAnotherInterface and useTagNamingAnotherTrait (ClassTemplateExtendsTest) are updated for it.
  • Unchanged: has invalid class X for a related class-like without type arguments (/** @implements Baz */ final class Bax implements Baz {}) and for a type that isn't a class-like (@implements int).

@github-actions

github-actions Bot commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

✅ Performance: unchanged · Types: unchanged

Project Memory (MB) Wall (s) Issues Weighted (types) Taint Dead code
✅ laravel 1 768 97.2 $\color{gray}{\textsf{+0.7\%}}$ 25 691 52 996 682 0
✅ symfony 3 596 267.4 $\color{gray}{\textsf{+1.5\%}}$ 50 610 $\color{red}{\textsf{+2}}$ $\color{green}{\textsf{-2}}$ 98 403 1 528 0
✅ doctrine-orm 380 15.4 $\color{gray}{\textsf{+1.1\%}}$ 3 481 6 143 0 0
✅ psl 617 20.1 $\color{gray}{\textsf{+0.2\%}}$ 1 375 5 615 1 0
✅ phpunit 455 20.1 $\color{gray}{\textsf{+2.9\%}}$ 1 731 3 410 18 0
✅ php-parser 226 13.8 $\color{gray}{\textsf{+0.2\%}}$ 17 154 21 245 0 0
✅ tempest 895 36.5 $\color{gray}{\textsf{-1.2\%}}$ 5 047 $\color{red}{\textsf{+2}}$ $\color{green}{\textsf{-2}}$ 10 528 252 0
✅ amphp-amp 45 1.1 29 49 0 0
✅ webmozarts-assert 272 3.4 $\color{gray}{\textsf{+0.3\%}}$ 577 2 720 0 0
✅ guzzle-promises 44 1.2 155 434 2 0
✅ monolog 135 4.2 913 2 479 10 0
✅ drupal 4 839 170.3 $\color{gray}{\textsf{-1.4\%}}$ 97 591 169 293 583 0
✅ wordpress 2 038 272.8 $\color{gray}{\textsf{+1.5\%}}$ 142 704 676 684 461 1
Total 15 311 923.6 $\color{gray}{\textsf{+0.7\%}}$ 347 058 $\color{red}{\textsf{+4}}$ $\color{green}{\textsf{-4}}$ 1 049 999 3 537 1
How to read this table
  • Memory: Psalm's own peak figure, threads=1. More than +5 % fails, unless the PR changes composer.json.
  • Wall: base and head run on the same runner; ±10 % is noise. Above +10 % warns, never fails. re-run: a reversed second run was taken and the faster kept.
  • Issues: head count over all categories, then $\color{red}{\textsf{+added}}$ $\color{green}{\textsf{-removed}}$ against base.
  • Weighted (types): type issues weighted by error level (levels 1–8 as is, always-errors 10, strictness checks 1). Taint and dead-code issues are not weighed. The projects' own code is pinned and their dependencies resolve identically for base and head, so a change means Psalm reports more, fewer or differently serious issues. A rise is not necessarily a regression.
  • Taint: head count of Tainted* issues, then $\color{orange}{\textsf{+added}}$ $\color{orange}{\textsf{-removed}}$ against base. Both are orange as either direction needs review: more can be new detection or false positives, fewer can be fixed false positives or lost detection.
  • Dead code: head count of unused-code issues, shown only when a run reported some (findUnusedCode). More is red, fewer is green.
  • Total: sum over the projects compared on both sides. Its wall time warns above +5 % (±5 % is noise); the other thresholds apply per project.
  • Colors: $\color{red}{\textsf{red}}$ past a fail or warn threshold (or more issues), $\color{green}{\textsf{green}}$ an improvement past noise (or fewer issues), $\color{orange}{\textsf{orange}}$ needs review, $\color{gray}{\textsf{gray}}$ noise.
  • Performance: regressed if a head run crashed or timed out or a memory or wall delta is red, else improved if one is green, else unchanged. Its icon is the check result: ❌ fail · ⚠️ warn · ✅ pass; the icon next to each project is that project's result, 💥 = not comparable: base crashed or timed out (counts as ⚠️).
  • Types (heading): direction of the total weighted change, increased · decreased · unchanged. Taint and Dead code (heading): added and removed counts, present only when non-zero. Informational, never fails the check.
✅ symfony: issues +2 −2

Memory 3 596 → 3 596 MB (+0.0 %) · Wall 263.4 → 267.4 s (+1.5 %)

Issue type added removed
InvalidDocblock 2 2

Changed in place (2)

@​@​ 2 places InvalidDocblock @​@​
  src/Symfony/Component/Form/Flow/FormFlow.php:29
  src/Symfony/Component/Form/Flow/FormFlowBuilder.php:30
- …must include the name of an implemented class, got IteratorAggregate<string, FormInterface…
+ …must include the name of an implemented interface, got IteratorAggregate<string, FormInterface…
✅ tempest: issues +2 −2

Memory 895 → 895 MB (+0.0 %) · Wall 36.9 → 36.5 s (−1.2 %)

Issue type added removed
InvalidDocblock 2 2

Changed in place (1)

@​@​ packages/support/src/Arr/ManipulatesArray.php:24 InvalidDocblock @​@​
- …must include the name of an implemented class, got ArrayAccess<TKey:ManipulatesArray as array-key, TValue…
- …must include the name of an implemented class, got Iterator<TKey:ManipulatesArray as array-key, TValue…
+ …must include the name of an implemented interface, got ArrayAccess<TKey:ManipulatesArray as array-key, TValue…
+ …must include the name of an implemented interface, got Iterator<TKey:ManipulatesArray as array-key, TValue…

head c8bf6b7 · base 9028ade (merge-base) · workflow run

@orklah orklah left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! The unified message is right, and the tests show it.

One thing to change: TGenericObject extends TNamedObject, so the new check at the top of the loop also catches generic types, and the existing if (!isset($related_classes[$generic_class_lc])) block further down can no longer be reached. The same message is now built in two places. Instead of adding a check, could you move the existing one above the TGenericObject check?

foreach ($union_type->getAtomicTypes() as $atomic_type) {
    if ($atomic_type instanceof TNamedObject
        && !isset($related_classes[strtolower($atomic_type->value)])
    ) {
        $storage->docblock_issues[] = new InvalidDocblock(
            $tag . ' must include the name of ' . $related_name . ', got ' . $atomic_type->getId(),
            new CodeLocation($this->file_scanner, $node, null, true),
        );

        continue;
    }

    if (!$atomic_type instanceof TGenericObject) {
        // has invalid class ...
        continue;
    }

    $generic_class_lc = strtolower($atomic_type->value);

    if ($this->reportStarArgument($storage, $node, $atomic_type, $tag)) {

(the comment above the check can go too). Could you also add the no-argument cases for the other two tags, which take the same path?

'useTagNamingAnotherTraitWithoutTypeArguments' => [
    'code' => '<?php
        /** @template T */
        trait T1 {}

        trait T2 {}

        final class C {
            /** @use T2 */
            use T1;
        }',
    'error_message' => '@template-use must include the name of a used trait, got T2',
],
'extendsTagNamingAnotherClassWithoutTypeArguments' => [
    'code' => '<?php
        /** @template T */
        class P {}

        final class Q {}

        /** @extends Q */
        final class C extends P {}',
    'error_message' => '@template-extends must include the name of an extended class, got Q',
],

…meo#6096

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@orklah orklah added the release:fix The PR will be included in 'Fixes' section of the release notes label Nov 23, 2026

@orklah orklah left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @jirkace!

@orklah
orklah merged commit 7cbbdf6 into vimeo:master Nov 23, 2026
72 of 73 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release:fix The PR will be included in 'Fixes' section of the release notes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

request for user-friendliness in template-hints errors

2 participants