Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 95eafee

Browse files
authoredJun 5, 2019
Merge pull request #111 from magento/array-merge-error
[Bug] ForeachArrayMergeSniff throws an error for inline control struc…
2 parents b2eee1a + 632c69b commit 95eafee

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed
 

‎Magento2/Sniffs/Performance/ForeachArrayMergeSniff.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ public function process(File $phpcsFile, $stackPtr)
4747
{
4848
$tokens = $phpcsFile->getTokens();
4949

50+
// If it's inline control structure we do nothing. PSR2 issue will be raised.
51+
if (!array_key_exists('scope_opener', $tokens[$stackPtr])) {
52+
return;
53+
}
5054
$scopeOpener = $tokens[$stackPtr]['scope_opener'];
5155
$scopeCloser = $tokens[$stackPtr]['scope_closer'];
5256

‎Magento2/Tests/Performance/ForeachArrayMergeUnitTest.inc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,11 @@ foreach ([] as $collection) {
4141
$selectBuilder->setColumns(array_merge($selectBuilder->getColumns(), $source));
4242
}
4343
}
44+
45+
foreach ([] as $item)
46+
// inline foreach
47+
$a = array_merge([], []);
48+
49+
foreach ([] as $item)
50+
// array_merge after inline foreach
51+
$a = array_merge([], []);

0 commit comments

Comments
 (0)
Please sign in to comment.