Skip to content

Commit

Permalink
fix: Require @template-implements or @implements for `IteratorIte…
Browse files Browse the repository at this point in the history
…mTypeSniff`, remove `@template-extends`
  • Loading branch information
gskema committed May 28, 2024
1 parent 3e8e46f commit b67d677
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ All notable changes to `phpcs-type-sniff` will be documented in this file.

Updates should follow the [Keep a CHANGELOG](http://keepachangelog.com/) principles.

## 81.6.4 - 2024-05-24
### Changed
- Require `@template-implements` or `@implements` for `IteratorItemTypeSniff`, remove `@template-extends`

## 81.6.3 - 2024-05-24
### Fixed
- Parse implemented interfaces using token instead of reflection, to avoid FatalError. Used in IteratorItemTypeSniff
Expand Down
4 changes: 2 additions & 2 deletions src/Sniffs/CodeElement/IteratorItemTypeSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,13 @@ public function process(File $file, CodeElementInterface $element, CodeElementIn

if ($element->getDocBlock()->getTagsByName('template-implements')) {
return;
} elseif ($element->getDocBlock()->getTagsByName('template-extends')) {
} elseif ($element->getDocBlock()->getTagsByName('implements')) {
return;
} else {
$originId = $this->addViolationId ? $element->getFqcn() : null;
SniffHelper::addViolation(
$file,
'Classes which implement IteratorAggregate must have "@template-implements IteratorAggregate<?>"'
'Classes which implement IteratorAggregate must have "@implements IteratorAggregate<?>" or "@template-implements ..."'
. ' doc tag with a specified item type or template type',
$element->getLine(),
static::CODE,
Expand Down
2 changes: 1 addition & 1 deletion tests/Sniffs/CompositeCodeElementSniffTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,7 @@ public static function dataProcess(): array
],
__DIR__ . '/fixtures/TestIterator0.php',
[
'009 Classes which implement IteratorAggregate must have "@template-implements IteratorAggregate<?>" doc tag with a specified item type or template type'
'009 Classes which implement IteratorAggregate must have "@implements IteratorAggregate<?>" or "@template-implements ..." doc tag with a specified item type or template type'
],
];

Expand Down

0 comments on commit b67d677

Please sign in to comment.