Skip to content

Commit 1ab9e6d

Browse files
author
Vincent Langlet
committed
🐛 Fix for doc comment string with space
1 parent 37ba7f6 commit 1ab9e6d

File tree

3 files changed

+25
-10
lines changed

3 files changed

+25
-10
lines changed

Symfony3Custom/Sniffs/Namespaces/UnusedUseSniff.php

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ public function register()
3232
public function process(File $phpcsFile, $stackPtr)
3333
{
3434
$tokens = $phpcsFile->getTokens();
35-
//T_DOC_COMMENT_STRING;PHPCS_T_DOC_COMMENT_TAG;
3635

3736
// Only check use statements in the global scope.
3837
if (empty($tokens[$stackPtr]['conditions']) === false) {
@@ -127,7 +126,7 @@ public function process(File $phpcsFile, $stackPtr)
127126
}
128127

129128
$classUsed = $phpcsFile->findNext(
130-
[T_STRING, T_DOC_COMMENT_STRING, T_RETURN_TYPE],
129+
[T_STRING, T_RETURN_TYPE],
131130
($classUsed + 1)
132131
);
133132
}
@@ -144,10 +143,20 @@ public function process(File $phpcsFile, $stackPtr)
144143

145144
// Check for @param Truc or @return Machin
146145
if ('T_DOC_COMMENT_STRING' === $token['type']) {
147-
// Handle @return Machin|Machine
148-
if (preg_match('/^'.$lowerClassName.'\|/i', $token['content']) === 1
149-
|| preg_match('/\|'.$lowerClassName.'\|/i', $token['content']) === 1
150-
|| preg_match('/\|'.$lowerClassName.'$/i', $token['content']) === 1) {
146+
if (trim(strtolower($token['content'])) === $lowerClassName
147+
// Handle @return Machin|Machine|AnotherMachin
148+
|| preg_match('/^'.$lowerClassName.'\|/i', trim($token['content'])) === 1
149+
|| preg_match('/\|'.$lowerClassName.'\|/i', trim($token['content'])) === 1
150+
|| preg_match('/\|'.$lowerClassName.'$/i', trim($token['content'])) === 1
151+
// Handle @var Machin $machin
152+
|| preg_match('/^'.$lowerClassName.' /i', trim($token['content'])) === 1
153+
// Handle @var $machin Machin
154+
|| preg_match('/ '.$lowerClassName.' /i', trim($token['content'])) === 1
155+
|| preg_match('/ '.$lowerClassName.'$/i', trim($token['content'])) === 1
156+
// Handle @var Machin|Machine $machin
157+
|| preg_match('/\|'.$lowerClassName.' /i', trim($token['content'])) === 1
158+
// Handle @var $machin Machin|Machine
159+
|| preg_match('/ '.$lowerClassName.'\|/i', trim($token['content'])) === 1) {
151160
$beforeUsage = $phpcsFile->findPrevious(
152161
Tokens::$emptyTokens,
153162
($classUsed - 1),

Symfony3Custom/Tests/Namespaces/UnusedUseUnitTest.inc

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use Truc;
1010
use Machin;
1111
use Machine;
1212
use Unused;
13+
use Client;
1314

1415
class Container
1516
{
@@ -18,12 +19,14 @@ class Container
1819
* @Route("/{id}")
1920
* @ORM\Column(type="integer")
2021
*
21-
* @param Toto
22-
* @var Truc
22+
* @param Toto $toto
23+
* @var Truc $truc
2324
* @return Machin|Machine
2425
*/
2526
function test (Bar $bar)
2627
{
28+
/** @var Client $client */
29+
2730
return;
2831
}
2932
}

Symfony3Custom/Tests/Namespaces/UnusedUseUnitTest.inc.fixed

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use ORM;
99
use Truc;
1010
use Machin;
1111
use Machine;
12+
use Client;
1213

1314
class Container
1415
{
@@ -17,12 +18,14 @@ class Container
1718
* @Route("/{id}")
1819
* @ORM\Column(type="integer")
1920
*
20-
* @param Toto
21-
* @var Truc
21+
* @param Toto $toto
22+
* @var Truc $truc
2223
* @return Machin|Machine
2324
*/
2425
function test (Bar $bar)
2526
{
27+
/** @var Client $client */
28+
2629
return;
2730
}
2831
}

0 commit comments

Comments
 (0)