Skip to content

Commit 76b5801

Browse files
committed
Resolved conflict between Generic.WhiteSpace.ScopeIndent and PSR2.Methods.FunctionCallSignature in a match block (ref #3255)
1 parent 7af643f commit 76b5801

File tree

6 files changed

+134
-4
lines changed

6 files changed

+134
-4
lines changed

src/Standards/Generic/Sniffs/WhiteSpace/ScopeIndentSniff.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -686,6 +686,11 @@ public function process(File $phpcsFile, $stackPtr)
686686
&& isset($tokens[$checkToken]['scope_opener']) === true
687687
) {
688688
$exact = true;
689+
if ($disableExactEnd > $checkToken) {
690+
if ($tokens[$checkToken]['conditions'] === $tokens[$disableExactEnd]['conditions']) {
691+
$exact = false;
692+
}
693+
}
689694

690695
$lastOpener = null;
691696
if (empty($openScopes) === false) {

src/Standards/Generic/Tests/WhiteSpace/ScopeIndentUnitTest.1.inc

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1503,6 +1503,36 @@ $value = match (
15031503
$value,
15041504
};
15051505

1506+
function toString(): string
1507+
{
1508+
return sprintf(
1509+
'%s',
1510+
match ($type) {
1511+
'foo' => 'bar',
1512+
},
1513+
);
1514+
}
1515+
1516+
$list = [
1517+
'fn' => function ($a) {
1518+
if ($a === true) {
1519+
echo 'hi';
1520+
}
1521+
},
1522+
'fn' => function ($a) {
1523+
if ($a === true) {
1524+
echo 'hi';
1525+
$list2 = [
1526+
'fn' => function ($a) {
1527+
if ($a === true) {
1528+
echo 'hi';
1529+
}
1530+
}
1531+
];
1532+
}
1533+
}
1534+
];
1535+
15061536
/* ADD NEW TESTS ABOVE THIS LINE AND MAKE SURE THAT THE 1 (space-based) AND 2 (tab-based) FILES ARE IN SYNC! */
15071537
?>
15081538

src/Standards/Generic/Tests/WhiteSpace/ScopeIndentUnitTest.1.inc.fixed

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1503,6 +1503,36 @@ $value = match (
15031503
$value,
15041504
};
15051505

1506+
function toString(): string
1507+
{
1508+
return sprintf(
1509+
'%s',
1510+
match ($type) {
1511+
'foo' => 'bar',
1512+
},
1513+
);
1514+
}
1515+
1516+
$list = [
1517+
'fn' => function ($a) {
1518+
if ($a === true) {
1519+
echo 'hi';
1520+
}
1521+
},
1522+
'fn' => function ($a) {
1523+
if ($a === true) {
1524+
echo 'hi';
1525+
$list2 = [
1526+
'fn' => function ($a) {
1527+
if ($a === true) {
1528+
echo 'hi';
1529+
}
1530+
}
1531+
];
1532+
}
1533+
}
1534+
];
1535+
15061536
/* ADD NEW TESTS ABOVE THIS LINE AND MAKE SURE THAT THE 1 (space-based) AND 2 (tab-based) FILES ARE IN SYNC! */
15071537
?>
15081538

src/Standards/Generic/Tests/WhiteSpace/ScopeIndentUnitTest.2.inc

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1503,6 +1503,36 @@ $value = match (
15031503
$value,
15041504
};
15051505

1506+
function toString(): string
1507+
{
1508+
return sprintf(
1509+
'%s',
1510+
match ($type) {
1511+
'foo' => 'bar',
1512+
},
1513+
);
1514+
}
1515+
1516+
$list = [
1517+
'fn' => function ($a) {
1518+
if ($a === true) {
1519+
echo 'hi';
1520+
}
1521+
},
1522+
'fn' => function ($a) {
1523+
if ($a === true) {
1524+
echo 'hi';
1525+
$list2 = [
1526+
'fn' => function ($a) {
1527+
if ($a === true) {
1528+
echo 'hi';
1529+
}
1530+
}
1531+
];
1532+
}
1533+
}
1534+
];
1535+
15061536
/* ADD NEW TESTS ABOVE THIS LINE AND MAKE SURE THAT THE 1 (space-based) AND 2 (tab-based) FILES ARE IN SYNC! */
15071537
?>
15081538

src/Standards/Generic/Tests/WhiteSpace/ScopeIndentUnitTest.2.inc.fixed

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1503,6 +1503,36 @@ $value = match (
15031503
$value,
15041504
};
15051505

1506+
function toString(): string
1507+
{
1508+
return sprintf(
1509+
'%s',
1510+
match ($type) {
1511+
'foo' => 'bar',
1512+
},
1513+
);
1514+
}
1515+
1516+
$list = [
1517+
'fn' => function ($a) {
1518+
if ($a === true) {
1519+
echo 'hi';
1520+
}
1521+
},
1522+
'fn' => function ($a) {
1523+
if ($a === true) {
1524+
echo 'hi';
1525+
$list2 = [
1526+
'fn' => function ($a) {
1527+
if ($a === true) {
1528+
echo 'hi';
1529+
}
1530+
}
1531+
];
1532+
}
1533+
}
1534+
];
1535+
15061536
/* ADD NEW TESTS ABOVE THIS LINE AND MAKE SURE THAT THE 1 (space-based) AND 2 (tab-based) FILES ARE IN SYNC! */
15071537
?>
15081538

src/Standards/Generic/Tests/WhiteSpace/ScopeIndentUnitTest.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -155,10 +155,15 @@ public function getErrorList($testFile='ScopeIndentUnitTest.inc')
155155
1489 => 1,
156156
1500 => 1,
157157
1503 => 1,
158-
1514 => 1,
159-
1515 => 1,
160-
1516 => 1,
161-
1517 => 1,
158+
1518 => 1,
159+
1520 => 1,
160+
1527 => 1,
161+
1529 => 1,
162+
1530 => 1,
163+
1544 => 1,
164+
1545 => 1,
165+
1546 => 1,
166+
1547 => 1,
162167
];
163168

164169
}//end getErrorList()

0 commit comments

Comments
 (0)