Conversation
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
Verify that DocCommentSpacing still reports errors for: - @extends before @template - @implements before @template - @implements before @extends - blank line between annotations in the same group
There was a problem hiding this comment.
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.xmlto use@template*inannotationsGroupsto 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 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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
@template*wildcard inannotationsGroupsso that@template,@template-covariant,@template-contravariant,@template-extends, and@template-implementsall share the same priority and preserve source order@templatebefore@template-covariant, which could silently break PHPStan's positional type parameter mappingphpunit.xml.distwith a testsuite so tests are discoveredtests/Data/from phpcs and phpstanFixes #14