Skip to content

Commit

Permalink
Improved annotations parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
kukulich committed Nov 14, 2022
1 parent d536acf commit 811468e
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
2 changes: 1 addition & 1 deletion SlevomatCodingStandard/Helpers/AnnotationHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ static function () use ($phpcsFile, $pointer): array {
$annotationName = $tokens[$annotationStartPointer]['content'];
$annotationParameters = null;
$annotationContent = null;
if (preg_match('~^(@[-a-zA-Z\\\\:]+)(?:\((.*)\))?(?:\\s+(.+))?($)~s', trim($annotationCode), $matches) !== 0) {
if (preg_match('~^(@[-a-zA-Z\\\\:]+)(?:\((.*)\))?(?:\\s+(.+))?(,|$)~s', trim($annotationCode), $matches) !== 0) {
$annotationName = $matches[1];
$annotationParameters = trim($matches[2]);
if ($annotationParameters === '') {
Expand Down
3 changes: 2 additions & 1 deletion tests/Sniffs/Namespaces/UnusedUsesSniffTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public function testUsedUseInAnnotationWithDisabledSearchAnnotations(): void
'searchAnnotations' => false,
]);

self::assertSame(78, $report->getErrorCount());
self::assertSame(79, $report->getErrorCount());

self::assertSniffError($report, 5, UnusedUsesSniff::CODE_UNUSED_USE, 'Type Assert is not used in this file.');
self::assertSniffError(
Expand Down Expand Up @@ -200,6 +200,7 @@ public function testUsedUseInAnnotationWithDisabledSearchAnnotations(): void
self::assertSniffError($report, 80, UnusedUsesSniff::CODE_UNUSED_USE, 'Type Conditional7 is not used in this file.');
self::assertSniffError($report, 81, UnusedUsesSniff::CODE_UNUSED_USE, 'Type Conditional8 is not used in this file.');
self::assertSniffError($report, 82, UnusedUsesSniff::CODE_UNUSED_USE, 'Type Conditional9 is not used in this file.');
self::assertSniffError($report, 84, UnusedUsesSniff::CODE_UNUSED_USE, 'Type Comma\After is not used in this file.');
}

public function testUsedUseInAnnotationWithEnabledSearchAnnotations(): void
Expand Down
13 changes: 12 additions & 1 deletion tests/Sniffs/Namespaces/data/unusedUsesInAnnotation.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@
use Conditional8;
use Conditional9;
use Something\Enum;
use Comma\After;

/**
* @ORM\Entity()
Expand Down Expand Up @@ -278,7 +279,6 @@ public function types($a, $b)
}

}

/**
* @CustomAssert\NotBlank(message=CustomAssert\AbstractConstraint::VIOLATION_IS_REQUIRED)
*/
Expand Down Expand Up @@ -308,3 +308,14 @@ enum SomeEnum
{
use Enum;
}

class CommaAfterAnnotation
{
/**
* @After\A(property="Packages", type="array",
* @After\B(type="object"),
* ),
* @After\C({"write-send"})
*/
public int $packages;
}

0 comments on commit 811468e

Please sign in to comment.