Skip to content

Use @template* wildcard to avoid reordering template annotations#15

Merged
JanTvrdik merged 4 commits intomasterfrom
add-template-variants-to-annotations-group
Mar 16, 2026
Merged

Use @template* wildcard to avoid reordering template annotations#15
JanTvrdik merged 4 commits intomasterfrom
add-template-variants-to-annotations-group

Conversation

@JanTvrdik
Copy link
Copy Markdown
Member

Summary

  • Use @template* wildcard in annotationsGroups so that @template, @template-covariant, @template-contravariant, @template-extends, and @template-implements all share the same priority and preserve source order
  • The previous explicit listing enforced @template before @template-covariant, which could silently break PHPStan's positional type parameter mapping
  • Add PHPUnit test verifying DocCommentSpacing accepts valid template annotation orderings
  • Configure phpunit.xml.dist with a testsuite so tests are discovered
  • Exclude tests/Data/ from phpcs and phpstan

Fixes #14

The order of @template, @template-covariant, and @template-contravariant
determines template parameter position in PHPStan's type system. Listing
them explicitly enforced an order that could silently break semantics.

Using @template* wildcard gives all template annotations the same priority,
so the sniff preserves their source order.

Also adds a PHPUnit test verifying DocCommentSpacing does not report errors
for valid template annotation orderings, and configures phpunit.xml.dist
with a testsuite so tests are actually discovered.

Fixes #14
Copilot AI review requested due to automatic review settings March 16, 2026 16:12
Verify that DocCommentSpacing still reports errors for:
- @extends before @template
- @implements before @template
- @implements before @extends
- blank line between annotations in the same group
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adjusts the DocCommentSpacing annotation grouping so @template* annotations keep their relative order (preserving PHPStan’s positional template parameter semantics), and adds coverage to prevent regressions.

Changes:

  • Update ShipMonkCodingStandard/ruleset.xml to use @template* in annotationsGroups to avoid reordering template annotations.
  • Add a PHPUnit test + fixture asserting DocCommentSpacing accepts valid @template* orderings.
  • Update tooling configs so tests are discovered and fixture files under tests/Data/ are excluded from phpcs/phpstan analysis.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
ShipMonkCodingStandard/ruleset.xml Switch template annotation group to @template* to preserve source order among template variants.
tests/DocCommentSpacingTest.php Adds a test that runs phpcs and asserts DocCommentSpacing emits no errors for valid template ordering.
tests/Data/DocCommentSpacing/TemplateAnnotationOrderCorrect.php Fixture docblocks covering several valid template ordering scenarios.
phpunit.xml.dist Adds a testsuite so PHPUnit discovers tests in tests/.
phpstan.neon.dist Excludes tests/Data from static analysis (fixture-only code).
phpcs.xml.dist Excludes tests/Data/ from coding standard checks (fixture-only code).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread tests/DocCommentSpacingTest.php Outdated
Comment on lines +29 to +34
public function testExtendsBeforeTemplateIsReported(): void
{
$output = self::runPhpcs(__DIR__ . '/Data/DocCommentSpacing/TemplateAnnotationOrderWrong.php');
self::assertSniffErrorOnLine(self::SNIFF_PREFIX . '.IncorrectOrderOfAnnotationsInGroup', $output, 7);
}

- Remove duplicate @param docblock on assertSniffErrorOnLine
- Add break after finding match in assertSniffErrorOnLine
- Consolidate 4 wrong-order test methods into one to avoid running
  phpcs 4 times on the same file
Trailing commas in function declarations require PHP 8.0+.
Setting php_version=70400 makes phpcs aware of the target version
so it won't enforce syntax unsupported on PHP 7.4.
@JanTvrdik JanTvrdik merged commit ca7fa07 into master Mar 16, 2026
7 checks passed
@JanTvrdik JanTvrdik deleted the add-template-variants-to-annotations-group branch March 16, 2026 16:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Annotation ordering should not enforce order between @template, @template-covariant, and @template-contravariant

2 participants