Skip to content

Commit d02296f

Browse files
committed
Resolved conflict between Generic.WhiteSpace.ScopeIndent and PSR2.Methods.FunctionCallSignature in a match block (ref #3255)
1 parent 377a467 commit d02296f

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
@@ -802,6 +802,11 @@ public function process(File $phpcsFile, $stackPtr)
802802
&& isset($tokens[$checkToken]['scope_opener']) === true
803803
) {
804804
$exact = true;
805+
if ($disableExactEnd > $checkToken) {
806+
if ($tokens[$checkToken]['conditions'] === $tokens[$disableExactEnd]['conditions']) {
807+
$exact = false;
808+
}
809+
}
805810

806811
$lastOpener = null;
807812
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
@@ -182,10 +182,15 @@ public function getErrorList($testFile='ScopeIndentUnitTest.inc')
182182
1489 => 1,
183183
1500 => 1,
184184
1503 => 1,
185-
1514 => 1,
186-
1515 => 1,
187-
1516 => 1,
188-
1517 => 1,
185+
1518 => 1,
186+
1520 => 1,
187+
1527 => 1,
188+
1529 => 1,
189+
1530 => 1,
190+
1544 => 1,
191+
1545 => 1,
192+
1546 => 1,
193+
1547 => 1,
189194
];
190195

191196
}//end getErrorList()

0 commit comments

Comments
 (0)