Skip to content

Commit 6a5a156

Browse files
author
Michael Nozdrevatykh
committed
Fixed problem in FullyQualifiedSniff with slashes in string params
1 parent 557350b commit 6a5a156

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

custom-standards/Flyeralarm/Sniffs/Classes/FullyQualifiedSniff.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,17 @@ private function getClassCall(File $phpcsFile, $stackPtr): string
4343

4444
switch ($tokens[$stackPtr]['code']) {
4545
case T_NEW:
46-
return $phpcsFile->getTokensAsString(
46+
$tokensAsString = $phpcsFile->getTokensAsString(
4747
$stackPtr,
4848
$phpcsFile->findEndOfStatement($stackPtr) - $stackPtr
4949
);
5050

51+
return substr(
52+
$tokensAsString,
53+
0,
54+
strpos($tokensAsString, '(')
55+
);
56+
5157
case T_DOUBLE_COLON:
5258
$classCallStart = $phpcsFile->findStartOfStatement($stackPtr);
5359

tests/rules/classes/allowed/FullyQualifiedSniff.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,11 @@ public function a()
1313
$className = RuntimeException::class;
1414
$a = new RuntimeException();
1515
}
16+
17+
public function b()
18+
{
19+
$a = new RuntimeException(
20+
'We can\'t explain'
21+
);
22+
}
1623
}

tests/rules/classes/not-allowed/FullyQualifiedSniff.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
// @expectedError Qualifier should be replaced with an import: "new \RuntimeException()"
3+
// @expectedError Qualifier should be replaced with an import: "new \RuntimeException"
44

55
namespace flyeralarm\Test;
66

0 commit comments

Comments
 (0)