Skip to content

Commit

Permalink
Re-add short closure sniff
Browse files Browse the repository at this point in the history
  • Loading branch information
jack-worman committed Dec 16, 2022
1 parent a52f35e commit 9ce31a7
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 32 deletions.
4 changes: 1 addition & 3 deletions bin/generate_testsuites.php
Expand Up @@ -30,9 +30,7 @@
// -- xkcd:221

$order = array_map(
function (): int {
return mt_rand();
},
fn(): int => mt_rand(),
$files
);
array_multisort($order, $files);
Expand Down
8 changes: 2 additions & 6 deletions bin/update-property-map.php
Expand Up @@ -100,9 +100,7 @@ function extractClassesFromStatements(array $statements): array
$file,
get_class($exception),
$exception->getMessage(),
implode("\n", array_map(function (LibXMLError $error): string {
return $error->message;
}, libxml_get_errors()))
implode("\n", array_map(fn(LibXMLError $error): string => $error->message, libxml_get_errors()))
);
libxml_clear_errors();
continue;
Expand Down Expand Up @@ -159,9 +157,7 @@ function extractClassesFromStatements(array $statements): array

function serializeArray(array $array, string $prefix): string
{
uksort($array, function (string $first, string $second): int {
return strtolower($first) <=> strtolower($second);
});
uksort($array, fn(string $first, string $second): int => strtolower($first) <=> strtolower($second));
$result = "[\n";
$localPrefix = $prefix . ' ';
foreach ($array as $key => $value) {
Expand Down
3 changes: 3 additions & 0 deletions phpcs.xml
Expand Up @@ -228,6 +228,9 @@
-->
<rule ref="SlevomatCodingStandard.PHP.ShortList"/>

<!-- https://github.com/slevomat/coding-standard/blob/master/doc/functions.md#slevomatcodingstandardfunctionsrequirearrowfunction- -->
<rule ref="SlevomatCodingStandard.Functions.RequireArrowFunction"/>

<!--
Forces uniform arrow function style
https://github.com/slevomat/coding-standard/blob/master/doc/functions.md#slevomatcodingstandardfunctionsarrowfunctiondeclaration-
Expand Down
22 changes: 10 additions & 12 deletions src/Psalm/Internal/Analyzer/Statements/Block/TryAnalyzer.php
Expand Up @@ -265,19 +265,17 @@ public static function analyze(

$catch_context->vars_in_scope[$catch_var_id] = new Union(
array_map(
static function (string $fq_catch_class) use ($codebase): TNamedObject {
return new TNamedObject(
$fq_catch_class,
false,
false,
version_compare(PHP_VERSION, '7.0.0dev', '>=')
&& strtolower($fq_catch_class) !== 'throwable'
&& $codebase->interfaceExists($fq_catch_class)
&& !$codebase->interfaceExtends($fq_catch_class, 'Throwable')
static fn(string $fq_catch_class): TNamedObject => new TNamedObject(
$fq_catch_class,
false,
false,
version_compare(PHP_VERSION, '7.0.0dev', '>=')
&& strtolower($fq_catch_class) !== 'throwable'
&& $codebase->interfaceExists($fq_catch_class)
&& !$codebase->interfaceExtends($fq_catch_class, 'Throwable')
? ['Throwable' => new TNamedObject('Throwable')]
: []
);
},
: [],
),
$fq_catch_classes
)
);
Expand Down
Expand Up @@ -391,9 +391,9 @@ private function getDocblock(): string
$modified_docblock = true;
$inferredThrowsClause = array_reduce(
$this->throwsExceptions,
function (string $throwsClause, string $exception) {
return $throwsClause === '' ? $exception : $throwsClause.'|'.$exception;
},
fn(string $throwsClause, string $exception) => $throwsClause === ''
? $exception
: $throwsClause.'|'.$exception,
''
);
if (array_key_exists('throws', $parsed_docblock->tags)) {
Expand Down
15 changes: 7 additions & 8 deletions src/Psalm/Report/ByIssueLevelAndTypeReport.php
Expand Up @@ -179,13 +179,12 @@ private function getFileReference($data): string

private function sortIssuesByLevelAndType(): void
{
usort($this->issues_data, function (IssueData $left, IssueData $right): int {
// negative error levels go to the top, followed by large positive levels, with level 1 at the bottom.
return [$left->error_level > 0, -$left->error_level, $left->type,
$left->file_path, $left->file_name, $left->line_from]
<=>
[$right->error_level > 0, -$right->error_level, $right->type,
$right->file_path, $right->file_name, $right->line_from];
});
usort(
$this->issues_data,
fn(IssueData $left, IssueData $right): int => [$left->error_level > 0, -$left->error_level,
$left->type, $left->file_path, $left->file_name, $left->line_from]
<=> [$right->error_level > 0, -$right->error_level, $right->type, $right->file_path, $right->file_name,
$right->line_from],
);
}
}

0 comments on commit 9ce31a7

Please sign in to comment.