Skip to content

Commit 51fdcd4

Browse files
committed
add testcase for multiline anonymous function
1 parent bbabb29 commit 51fdcd4

3 files changed

Lines changed: 30 additions & 0 deletions

File tree

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1152,6 +1152,12 @@ public function process(File $phpcsFile, int $stackPtr)
11521152
StatusWriter::write("=> indent will be set to $futureIndent at token $opener ($type)", 1);
11531153
}
11541154

1155+
// If it is a closure, jump to the future.
1156+
if ($tokens[$i]['code'] === T_CLOSURE) {
1157+
$i = $opener;
1158+
$currentIndent = $futureIndent;
1159+
}
1160+
11551161
continue;
11561162
}
11571163

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,3 +79,15 @@ return true;
7979
}
8080
};
8181
}
82+
83+
// Edge case: anonymous function.
84+
register_shutdown_function(
85+
static function () use (
86+
$errorMsg,
87+
$errorArray
88+
) {
89+
if (empty($errorMsg) === false) {
90+
fwrite(STDERR, $errorMsg);
91+
}
92+
}
93+
);

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,3 +79,15 @@ if (class_exists('ConditionalClass') === false) {
7979
}
8080
};
8181
}
82+
83+
// Edge case: anonymous function.
84+
register_shutdown_function(
85+
static function () use (
86+
$errorMsg,
87+
$errorArray
88+
) {
89+
if (empty($errorMsg) === false) {
90+
fwrite(STDERR, $errorMsg);
91+
}
92+
}
93+
);

0 commit comments

Comments
 (0)