From fa766ac0c76bf83e0e018a73e13fbd0a2d328a42 Mon Sep 17 00:00:00 2001 From: Vincent Langlet Date: Wed, 27 May 2020 22:54:28 +0200 Subject: [PATCH] :sparkles: Support intersection --- .../Sniffs/Namespaces/UnusedUseSniff.php | 2 +- .../Tests/Namespaces/UnusedUseUnitTest.inc | 21 +++++++++++++++++++ .../Namespaces/UnusedUseUnitTest.inc.fixed | 19 +++++++++++++++++ .../Tests/Namespaces/UnusedUseUnitTest.php | 2 ++ 4 files changed, 43 insertions(+), 1 deletion(-) diff --git a/SymfonyCustom/Sniffs/Namespaces/UnusedUseSniff.php b/SymfonyCustom/Sniffs/Namespaces/UnusedUseSniff.php index c6d9850..ca58df6 100644 --- a/SymfonyCustom/Sniffs/Namespaces/UnusedUseSniff.php +++ b/SymfonyCustom/Sniffs/Namespaces/UnusedUseSniff.php @@ -315,7 +315,7 @@ private function isClassUsed(File $phpcsFile, int $usePtr, int $classPtr): bool || ('class' === $type && ((T_DOC_COMMENT_STRING === $tokens[$classUsed]['code'] && preg_match( - '/(\s|\||\(|\<|\,|^)'.preg_quote($searchName, '/').'(\s|\||\\\\|\<|\,|\>|$|\[\])/i', + '/(\s|\||\&|\(|\<|\,|^)'.preg_quote($searchName, '/').'(\s|\||\&|\\\\|\<|\,|\>|\}|$|\[\])/i', $tokens[$classUsed]['content'] )) || (T_DOC_COMMENT_TAG === $tokens[$classUsed]['code'] diff --git a/SymfonyCustom/Tests/Namespaces/UnusedUseUnitTest.inc b/SymfonyCustom/Tests/Namespaces/UnusedUseUnitTest.inc index 8a1fa37..48c8223 100644 --- a/SymfonyCustom/Tests/Namespaces/UnusedUseUnitTest.inc +++ b/SymfonyCustom/Tests/Namespaces/UnusedUseUnitTest.inc @@ -150,3 +150,24 @@ function ($a) { return null; } + +namespace PhpDoc; + +use Some\Key; +use Some\Key2; +use Some\Value; +use Some\Value2; +use Some\Foo; +use Some\Bar; +use Some\Baz; + +/** + * @param array{Key: Value, Key2: Value2} $a + * @param Foo&Bar&Baz $a + * + * @return null + */ +function ($a) +{ + return null; +} diff --git a/SymfonyCustom/Tests/Namespaces/UnusedUseUnitTest.inc.fixed b/SymfonyCustom/Tests/Namespaces/UnusedUseUnitTest.inc.fixed index a2ad6fb..0b98b1d 100644 --- a/SymfonyCustom/Tests/Namespaces/UnusedUseUnitTest.inc.fixed +++ b/SymfonyCustom/Tests/Namespaces/UnusedUseUnitTest.inc.fixed @@ -137,3 +137,22 @@ function ($a) { return null; } + +namespace PhpDoc; + +use Some\Value; +use Some\Value2; +use Some\Foo; +use Some\Bar; +use Some\Baz; + +/** + * @param array{Key: Value, Key2: Value2} $a + * @param Foo&Bar&Baz $a + * + * @return null + */ +function ($a) +{ + return null; +} diff --git a/SymfonyCustom/Tests/Namespaces/UnusedUseUnitTest.php b/SymfonyCustom/Tests/Namespaces/UnusedUseUnitTest.php index 376bd55..693da38 100644 --- a/SymfonyCustom/Tests/Namespaces/UnusedUseUnitTest.php +++ b/SymfonyCustom/Tests/Namespaces/UnusedUseUnitTest.php @@ -35,6 +35,8 @@ protected function getErrorList(): array 127 => 1, 128 => 1, 129 => 1, + 156 => 1, + 157 => 1, ]; }