Skip to content

Commit fbb0a08

Browse files
authored
PhpdocOnlyAllowedAnnotationsFixer - fix for invalid tag (#312)
1 parent 21d5178 commit fbb0a08

File tree

3 files changed

+18
-4
lines changed

3 files changed

+18
-4
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
[![CI Status](https://github.com/kubawerlos/php-cs-fixer-custom-fixers/workflows/CI/badge.svg?branch=master&event=push)](https://github.com/kubawerlos/php-cs-fixer-custom-fixers/actions)
1010
[![Code coverage](https://img.shields.io/coveralls/github/kubawerlos/php-cs-fixer-custom-fixers/master.svg)](https://coveralls.io/github/kubawerlos/php-cs-fixer-custom-fixers?branch=master)
11-
![Tests](https://img.shields.io/badge/tests-2176-brightgreen.svg)
11+
![Tests](https://img.shields.io/badge/tests-2177-brightgreen.svg)
1212
[![Mutation testing badge](https://badge.stryker-mutator.io/github.com/kubawerlos/php-cs-fixer-custom-fixers/master)](https://stryker-mutator.github.io)
1313
[![Psalm type coverage](https://shepherd.dev/github/kubawerlos/php-cs-fixer-custom-fixers/coverage.svg)](https://shepherd.dev/github/kubawerlos/php-cs-fixer-custom-fixers)
1414

src/Fixer/PhpdocOnlyAllowedAnnotationsFixer.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,12 @@ public function fix(\SplFileInfo $file, Tokens $tokens): void
9797
$docBlock = new DocBlock($token->getContent());
9898

9999
foreach ($docBlock->getAnnotations() as $annotation) {
100-
Preg::match('/@([a-zA-Z0-9\Q_-\\\E]+)/', $annotation->getContent(), $matches);
101-
102-
if (\in_array($matches[1], $this->elements, true)) {
100+
if (Preg::match('/@([a-zA-Z0-9_\\-\\\\]+)/', $annotation->getContent(), $matches) === 1
101+
&& \in_array($matches[1], $this->elements, true)
102+
) {
103103
continue;
104104
}
105+
105106
$annotation->remove();
106107
}
107108

tests/Fixer/PhpdocOnlyAllowedAnnotationsFixerTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,5 +121,18 @@ public static function provideFixCases(): iterable
121121
',
122122
['elements' => ['foo', 'bar']],
123123
];
124+
125+
yield [
126+
'<?php
127+
/**
128+
*/
129+
',
130+
'<?php
131+
/**
132+
* @#
133+
* @return Foo
134+
*/
135+
',
136+
];
124137
}
125138
}

0 commit comments

Comments
 (0)