Skip to content

Commit 6f0c9ac

Browse files
authored
Merge pull request #125 from magento-commerce/imported-sivaschenko-magento-coding-standard-336
[Imported] Fixed AutogeneratedClassNotInConstructorSniff for specific code constructions
2 parents fb3c3ee + 77885d7 commit 6f0c9ac

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

Magento2/Sniffs/PHP/AutogeneratedClassNotInConstructorSniff.php

+7-4
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,13 @@ public function process(File $phpcsFile, $stackPtr)
4747
}
4848

4949
if (!isset($tokens[$stackPtr + 4]) || $tokens[$stackPtr + 4]['code'] !== T_SEMICOLON) {
50-
$this->validateRequestedClass(
51-
$phpcsFile,
52-
$phpcsFile->findNext(T_OBJECT_OPERATOR, $stackPtr)
53-
);
50+
$arrowPosition = $phpcsFile->findNext(T_OBJECT_OPERATOR, $stackPtr);
51+
if ($arrowPosition !== false) {
52+
$this->validateRequestedClass(
53+
$phpcsFile,
54+
$arrowPosition
55+
);
56+
}
5457
return;
5558
}
5659

Magento2/Tests/PHP/AutogeneratedClassNotInConstructorUnitTest.2.php.inc

+5
Original file line numberDiff line numberDiff line change
@@ -36,5 +36,10 @@ class Bad
3636
ObjectManager::getInstance()
3737
->get(\Full\Class\NameFactory::class);
3838
}
39+
40+
private function foo(): void
41+
{
42+
ObjectManager::getInstance() ;
43+
}
3944
}
4045

0 commit comments

Comments
 (0)