Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Applied ClosureToArrowFunctionRector #7315

Merged
merged 2 commits into from Jan 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 1 addition & 3 deletions examples/plugins/ClassUnqualifier.php
Expand Up @@ -41,9 +41,7 @@ public static function afterClassLikeExistenceCheck(
$new_candidate_type = implode(
'',
array_map(
function ($f) {
return $f[0];
},
fn($f) => $f[0],
$type_tokens
)
);
Expand Down
11 changes: 11 additions & 0 deletions phpcs.xml
Expand Up @@ -222,4 +222,15 @@
https://github.com/slevomat/coding-standard/#slevomatcodingstandardphpshortlist-
-->
<rule ref="SlevomatCodingStandard.PHP.ShortList"/>

<!--
Requires arrow functions.
https://github.com/slevomat/coding-standard/#slevomatcodingstandardfunctionsrequirearrowfunction-
-->
<rule ref="SlevomatCodingStandard.Functions.RequireArrowFunction">
<properties>
<property name="enabled" value="true"/>
<property name="allowNested" value="true"/>
</properties>
</rule>
</ruleset>
5 changes: 2 additions & 3 deletions src/Psalm/Config.php
Expand Up @@ -2080,13 +2080,12 @@ public function visitComposerAutoloadFiles(ProjectAnalyzer $project_analyzer, ?P

if (file_exists($vendor_autoload_files_path)) {
$this->include_collector->runAndCollect(
function () use ($vendor_autoload_files_path) {
fn(): array =>
/**
* @psalm-suppress UnresolvableInclude
* @var string[]
*/
return require $vendor_autoload_files_path;
}
require $vendor_autoload_files_path
);
}

Expand Down
4 changes: 1 addition & 3 deletions src/Psalm/Config/Creator.php
Expand Up @@ -136,9 +136,7 @@ public static function getLevel(array $issues, int $counted_types): int
// remove any issues where < 0.1% of expressions are affected
$filtered_issues = array_filter(
$issues,
function ($amount): bool {
return $amount > 0.1;
}
fn($amount): bool => $amount > 0.1
);

if (array_sum($filtered_issues) > 0.5) {
Expand Down
4 changes: 1 addition & 3 deletions src/Psalm/Config/FileFilter.php
Expand Up @@ -406,9 +406,7 @@ public static function loadFromXMLElement(
private static function isRegularExpression(string $string): bool
{
set_error_handler(
function (): bool {
return false;
},
fn(): bool => false,
E_WARNING
);
$is_regexp = preg_match($string, '') !== false;
Expand Down
32 changes: 14 additions & 18 deletions src/Psalm/Config/IssueHandler.php
Expand Up @@ -149,26 +149,22 @@ public static function getAllIssueTypes(): array
{
return array_filter(
array_map(
function (string $file_name): string {
return substr($file_name, 0, -4);
},
fn(string $file_name): string => substr($file_name, 0, -4),
scandir(dirname(__DIR__) . '/Issue', SCANDIR_SORT_NONE)
),
function (string $issue_name): bool {
return $issue_name !== ''
&& $issue_name !== 'MethodIssue'
&& $issue_name !== 'PropertyIssue'
&& $issue_name !== 'FunctionIssue'
&& $issue_name !== 'ArgumentIssue'
&& $issue_name !== 'VariableIssue'
&& $issue_name !== 'ClassIssue'
&& $issue_name !== 'CodeIssue'
&& $issue_name !== 'PsalmInternalError'
&& $issue_name !== 'ParseError'
&& $issue_name !== 'PluginIssue'
&& $issue_name !== 'MixedIssue'
&& $issue_name !== 'MixedIssueTrait';
}
fn(string $issue_name): bool => $issue_name !== ''
&& $issue_name !== 'MethodIssue'
&& $issue_name !== 'PropertyIssue'
&& $issue_name !== 'FunctionIssue'
&& $issue_name !== 'ArgumentIssue'
&& $issue_name !== 'VariableIssue'
&& $issue_name !== 'ClassIssue'
&& $issue_name !== 'CodeIssue'
&& $issue_name !== 'PsalmInternalError'
&& $issue_name !== 'ParseError'
&& $issue_name !== 'PluginIssue'
&& $issue_name !== 'MixedIssue'
&& $issue_name !== 'MixedIssueTrait'
);
}
}
35 changes: 14 additions & 21 deletions src/Psalm/ErrorBaseline.php
Expand Up @@ -48,9 +48,7 @@ public static function countTotalIssues(array $existingIssues): int
/**
* @param array{o:int, s:array<int, string>} $existingIssue
*/
function (int $carry, array $existingIssue): int {
return $carry + $existingIssue['o'];
},
fn(int $carry, array $existingIssue): int => $carry + $existingIssue['o'],
0
);
}
Expand Down Expand Up @@ -260,9 +258,7 @@ private static function writeToFile(
('php:' . PHP_VERSION),
],
array_map(
function (string $extension): string {
return $extension . ':' . phpversion($extension);
},
fn(string $extension): string => $extension . ':' . phpversion($extension),
$extensions
)
)));
Expand Down Expand Up @@ -299,21 +295,18 @@ function (string $extension): string {
/**
* @param string[] $matches
*/
function (array $matches): string {
return
'<files' .
"\n " .
$matches[1] .
"\n" .
' php-version="' .
"\n " .
str_replace('&#10;&#9;', "\n ", $matches[2]).
"\n" .
' "' .
"\n" .
$matches[3] .
"\n";
},
fn(array $matches): string => '<files' .
"\n " .
$matches[1] .
"\n" .
' php-version="' .
"\n " .
str_replace('&#10;&#9;', "\n ", $matches[2]).
"\n" .
' "' .
"\n" .
$matches[3] .
"\n",
$baselineDoc->saveXML()
);

Expand Down
12 changes: 3 additions & 9 deletions src/Psalm/Internal/Algebra.php
Expand Up @@ -200,9 +200,7 @@ public static function simplifyCNF(array $clauses): array
$clause_var_possibilities = array_values(
array_filter(
$clause_b->possibilities[$clause_var],
function (string $possible_type) use ($negated_clause_type): bool {
return $possible_type !== $negated_clause_type;
}
fn(string $possible_type): bool => $possible_type !== $negated_clause_type
)
);

Expand Down Expand Up @@ -307,9 +305,7 @@ public static function getTruthsFromFormula(
// if there's only one active clause, return all the non-negation clause members ORed together
$things_that_can_be_said = array_filter(
$possible_types,
function (string $possible_type): bool {
return $possible_type[0] !== '!';
}
fn(string $possible_type): bool => $possible_type[0] !== '!'
);

if ($things_that_can_be_said && count($things_that_can_be_said) === count($possible_types)) {
Expand Down Expand Up @@ -595,9 +591,7 @@ public static function negateFormula(array $clauses): array
{
$clauses = array_filter(
$clauses,
function ($clause) {
return $clause->reconcilable;
}
fn($clause) => $clause->reconcilable
);

if (!$clauses) {
Expand Down
12 changes: 4 additions & 8 deletions src/Psalm/Internal/Analyzer/ClassAnalyzer.php
Expand Up @@ -898,11 +898,9 @@ public static function addContextProperties(
if ($property_type_location && !$fleshed_out_type->isMixed()) {
$stmt = array_filter(
$stmts,
function ($stmt) use ($property_name): bool {
return $stmt instanceof PhpParser\Node\Stmt\Property
&& isset($stmt->props[0]->name->name)
&& $stmt->props[0]->name->name === $property_name;
}
fn($stmt): bool => $stmt instanceof PhpParser\Node\Stmt\Property
&& isset($stmt->props[0]->name->name)
&& $stmt->props[0]->name->name === $property_name
);

$suppressed = [];
Expand Down Expand Up @@ -1948,9 +1946,7 @@ public static function analyzeClassMethodReturnType(
}

$overridden_method_ids = array_map(
function ($method_id) {
return $method_id->__toString();
},
fn($method_id) => $method_id->__toString(),
$overridden_method_ids
);

Expand Down
Expand Up @@ -239,9 +239,7 @@ public static function verifyReturnType(
if ($number_of_types > 1) {
$inferred_return_type_parts = array_filter(
$inferred_return_type_parts,
static function (Union $union_type): bool {
return !$union_type->isNever();
}
static fn(Union $union_type): bool => !$union_type->isNever()
);
}

Expand Down
40 changes: 10 additions & 30 deletions src/Psalm/Internal/Analyzer/ScopeAnalyzer.php
Expand Up @@ -151,9 +151,7 @@ public static function getControlActions(

$all_leave = !array_filter(
$if_statement_actions,
function ($action) {
return $action === self::ACTION_NONE;
}
fn($action) => $action === self::ACTION_NONE
);

$else_statement_actions = $stmt->else
Expand All @@ -168,9 +166,7 @@ function ($action) {
&& $else_statement_actions
&& !array_filter(
$else_statement_actions,
function ($action) {
return $action === self::ACTION_NONE;
}
fn($action) => $action === self::ACTION_NONE
);

$all_elseif_actions = [];
Expand All @@ -187,9 +183,7 @@ function ($action) {
$all_leave = $all_leave
&& !array_filter(
$elseif_control_actions,
function ($action) {
return $action === self::ACTION_NONE;
}
fn($action) => $action === self::ACTION_NONE
);

$all_elseif_actions = array_merge($elseif_control_actions, $all_elseif_actions);
Expand All @@ -216,9 +210,7 @@ function ($action) {
$else_statement_actions,
$all_elseif_actions
),
function ($action) {
return $action !== self::ACTION_NONE;
}
fn($action) => $action !== self::ACTION_NONE
);
}

Expand Down Expand Up @@ -278,9 +270,7 @@ function ($action) {

$all_case_actions = array_filter(
$all_case_actions,
function ($action) {
return $action !== self::ACTION_NONE;
}
fn($action) => $action !== self::ACTION_NONE
);

if ($has_default_terminator || $stmt->getAttribute('allMatched', false)) {
Expand All @@ -307,9 +297,7 @@ function ($action) {

$control_actions = array_filter(
array_merge($control_actions, $loop_actions),
function ($action) {
return $action !== self::ACTION_NONE;
}
fn($action) => $action !== self::ACTION_NONE
);

if ($stmt instanceof PhpParser\Node\Stmt\While_
Expand Down Expand Up @@ -365,9 +353,7 @@ function ($action) {

$try_leaves = !array_filter(
$try_statement_actions,
function ($action) {
return $action === self::ACTION_NONE;
}
fn($action) => $action === self::ACTION_NONE
);

$all_catch_actions = [];
Expand All @@ -386,9 +372,7 @@ function ($action) {
$all_leave = $all_leave
&& !array_filter(
$catch_actions,
function ($action) {
return $action === self::ACTION_NONE;
}
fn($action) => $action === self::ACTION_NONE
);

if (!$all_leave) {
Expand Down Expand Up @@ -425,9 +409,7 @@ function ($action) {
return array_merge(
array_filter(
$control_actions,
function ($action) {
return $action !== self::ACTION_NONE;
}
fn($action) => $action !== self::ACTION_NONE
),
$finally_statement_actions
);
Expand All @@ -436,9 +418,7 @@ function ($action) {

$control_actions = array_filter(
array_merge($control_actions, $try_statement_actions),
function ($action) {
return $action !== self::ACTION_NONE;
}
fn($action) => $action !== self::ACTION_NONE
);
}
}
Expand Down
Expand Up @@ -1000,9 +1000,7 @@ public static function getKeyValueParamsForTraversableObject(
: array_values(
array_map(
/** @param array<string, Union> $arr */
function (array $arr) use ($iterator_atomic_type): Union {
return $arr[$iterator_atomic_type->value] ?? Type::getMixed();
},
fn(array $arr): Union => $arr[$iterator_atomic_type->value] ?? Type::getMixed(),
$generic_storage->template_types
)
);
Expand Down
Expand Up @@ -76,11 +76,9 @@ public static function analyze(
$entry_clauses = array_values(
array_filter(
$entry_clauses,
function (Clause $c) use ($changed_var_ids): bool {
return count($c->possibilities) > 1
|| $c->wedge
|| !isset($changed_var_ids[array_keys($c->possibilities)[0]]);
}
fn(Clause $c): bool => count($c->possibilities) > 1
|| $c->wedge
|| !isset($changed_var_ids[array_keys($c->possibilities)[0]])
)
);
}
Expand Down Expand Up @@ -209,9 +207,7 @@ function (Clause $c) use ($changed_var_ids): bool {
*
* @return true
*/
function (Union $_): bool {
return true;
},
fn(Union $_): bool => true,
array_diff_key(
$if_conditional_context->vars_in_scope,
$pre_condition_vars_in_scope,
Expand Down