Skip to content

Commit de99e8b

Browse files
committed
#319: Corrected regex
1 parent c4e2eca commit de99e8b

3 files changed

+7
-7
lines changed

Diff for: Magento2/Sniffs/PHP/AutogeneratedClassNotInConstructorSniff.php

+2-6
Original file line numberDiff line numberDiff line change
@@ -142,14 +142,10 @@ private function getObjectManagerVariableName(File $phpcsFile, int $stackPtr): ?
142142
*/
143143
private function getRequestedClass(File $phpcsFile, int $callerPosition): ?string
144144
{
145-
if (!isset($phpcsFile->getTokens()[$callerPosition + 10])) {
146-
return null;
147-
}
148-
149145
$matches = [];
150146
$found = preg_match(
151-
'/->(get|create)\(([A-Za-z]+)::class/',
152-
$phpcsFile->getTokensAsString($callerPosition, 7),
147+
'/->(get|create)\(([A-Za-z\\\]+)::class/',
148+
$phpcsFile->getTokensAsString($callerPosition, $phpcsFile->findNext(T_CLOSE_PARENTHESIS, $callerPosition)),
153149
$matches
154150
);
155151

Diff for: Magento2/Tests/PHP/AutogeneratedClassNotInConstructorUnitTest.2.php.inc

+3
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ class Bad
3232
$this->eavSetup = $objectManager
3333
->get(EavSetupFactory::class)
3434
->create(['setup' => $this->setup]);
35+
36+
ObjectManager::getInstance()
37+
->get(\Full\Class\NameFactory::class);
3538
}
3639
}
3740

Diff for: Magento2/Tests/PHP/AutogeneratedClassNotInConstructorUnitTest.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ public function getErrorList($filename = '')
2626
return [
2727
22 => 1,
2828
28 => 1,
29-
33 => 1
29+
33 => 1,
30+
37 => 1
3031
];
3132
}
3233
return [];

0 commit comments

Comments
 (0)