diff --git a/SlevomatCodingStandard/Helpers/AnnotationHelper.php b/SlevomatCodingStandard/Helpers/AnnotationHelper.php index 946b6a23a..2a2d4baa0 100644 --- a/SlevomatCodingStandard/Helpers/AnnotationHelper.php +++ b/SlevomatCodingStandard/Helpers/AnnotationHelper.php @@ -66,7 +66,7 @@ public static function getAnnotations(\PHP_CodeSniffer\Files\File $codeSnifferFi $annotationName = $tokens[$i]['content']; $annotationParameters = null; $annotationContent = null; - if (preg_match('~^(@[a-zA-Z\\\\]+)(?:\(([^)]*)\))?(?:\\s+(.+))?($)~s', $annotationCode, $matches)) { + if (preg_match('~^(@[a-zA-Z\\\\]+)(?:\((.*?)\))?(?:\\s+(.+))?($)~s', $annotationCode, $matches)) { $annotationName = $matches[1]; $annotationParameters = trim($matches[2]); if ($annotationParameters === '') { diff --git a/tests/Helpers/AnnotationHelperTest.php b/tests/Helpers/AnnotationHelperTest.php index 4df92d71b..d9b75a347 100644 --- a/tests/Helpers/AnnotationHelperTest.php +++ b/tests/Helpers/AnnotationHelperTest.php @@ -70,6 +70,14 @@ public function testFunctionWithParametrizedAnnotation(): void $this->assertNull($annotations[0]->getContent()); } + public function testFunctionWithParametrizedAnnotationContainingParenthesis(): void + { + $annotations = AnnotationHelper::getAnnotationsByName($this->getTestedCodeSnifferFile(), $this->findFunctionPointerByName($this->getTestedCodeSnifferFile(), 'withParametrizedAnnotationContainingParenthesis'), '@Security'); + $this->assertCount(1, $annotations); + $this->assertSame('"is_granted(\'ROLE_ADMIN\')"', $annotations[0]->getParameters()); + $this->assertNull($annotations[0]->getContent()); + } + public function testFunctionWithMultilineParametrizedAnnotation(): void { $annotations = AnnotationHelper::getAnnotationsByName($this->getTestedCodeSnifferFile(), $this->findFunctionPointerByName($this->getTestedCodeSnifferFile(), 'withMultilineParametrizedAnnotation'), '@Route'); diff --git a/tests/Helpers/data/annotation.php b/tests/Helpers/data/annotation.php index ca31a9c31..be91c4502 100644 --- a/tests/Helpers/data/annotation.php +++ b/tests/Helpers/data/annotation.php @@ -36,6 +36,11 @@ public function withAnnotation($b, $c); */ public function withParametrizedAnnotation(); + /** + * @Security("is_granted('ROLE_ADMIN')") + */ + public function withParametrizedAnnotationContainingParenthesis(); + /** * @Assert\Callback() */ diff --git a/tests/Sniffs/TypeHints/TypeHintDeclarationSniffTest.php b/tests/Sniffs/TypeHints/TypeHintDeclarationSniffTest.php index 77e7dfe3d..af0c3b243 100644 --- a/tests/Sniffs/TypeHints/TypeHintDeclarationSniffTest.php +++ b/tests/Sniffs/TypeHints/TypeHintDeclarationSniffTest.php @@ -22,6 +22,7 @@ public function testNoErrors(): void '@see', '@Assert\Callback', '@Something\\', + '@Security', ], ])); } diff --git a/tests/Sniffs/TypeHints/data/typeHintDeclarationNoErrors.php b/tests/Sniffs/TypeHints/data/typeHintDeclarationNoErrors.php index 03d382ab0..2213fe225 100644 --- a/tests/Sniffs/TypeHints/data/typeHintDeclarationNoErrors.php +++ b/tests/Sniffs/TypeHints/data/typeHintDeclarationNoErrors.php @@ -654,4 +654,12 @@ public function parameterHasDescriptionContainingVariable(bool $foo, int $bar) : { } + /** + * @Security("is_granted('ROLE_ADMIN')") + */ + public function usefullSymfonySecurityAnnotation() + { + + } + }