Skip to content

Commit

Permalink
static lambda (#2505)
Browse files Browse the repository at this point in the history
Lambdas not (indirect) referencing $this must be declared static.
  • Loading branch information
MathiasReker committed Jun 16, 2022
1 parent f2035db commit 20e187c
Show file tree
Hide file tree
Showing 11 changed files with 12 additions and 12 deletions.
4 changes: 2 additions & 2 deletions src/Application/FileSystem/RemovedAndAddedFilesCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public function getAddedFilesWithContent(): array
{
return array_filter(
$this->addedFiles,
fn (AddedFileInterface $addedFile): bool => $addedFile instanceof AddedFileWithContent
static fn (AddedFileInterface $addedFile): bool => $addedFile instanceof AddedFileWithContent
);
}

Expand All @@ -90,7 +90,7 @@ public function getAddedFilesWithNodes(): array
{
return array_filter(
$this->addedFiles,
fn (AddedFileInterface $addedFile): bool => $addedFile instanceof AddedFileWithNodes
static fn (AddedFileInterface $addedFile): bool => $addedFile instanceof AddedFileWithNodes
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function configure(array $configuration): self
$this->ensureClassIsConfigurable($this->id);

// decorate with value object inliner so Symfony understands, see https://getrector.org/blog/2020/09/07/how-to-inline-value-object-in-symfony-php-config
array_walk_recursive($configuration, function (&$value) {
array_walk_recursive($configuration, static function (&$value) {
if (is_object($value)) {
$value = ValueObjectInliner::inline($value);
}
Expand Down
2 changes: 1 addition & 1 deletion src/FileSystem/FilesystemTweaker.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,6 @@ private function foundInGlob(string $path): array
/** @var string[] $paths */
$paths = (array) glob($path);

return array_filter($paths, fn (string $path): bool => file_exists($path));
return array_filter($paths, static fn (string $path): bool => file_exists($path));
}
}
2 changes: 1 addition & 1 deletion src/NodeManipulator/BinaryOpManipulator.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ private function normalizeCondition(callable|string $condition): callable
return $condition;
}

return fn (Node $node): bool => is_a($node, $condition, true);
return static fn (Node $node): bool => is_a($node, $condition, true);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/NodeManipulator/ClassManipulator.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public function getPrivatePropertyNames(Class_ $class): array
{
$privateProperties = array_filter(
$class->getProperties(),
fn (Property $property): bool => $property->isPrivate()
static fn (Property $property): bool => $property->isPrivate()
);

return $this->nodeNameResolver->getNames($privateProperties);
Expand Down
2 changes: 1 addition & 1 deletion src/NodeManipulator/ClassMethodAssignManipulator.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ private function filterOutReferencedVariables(array $variableAssigns, ClassMetho
*/
private function filterOutMultiAssigns(array $readOnlyVariableAssigns): array
{
return array_filter($readOnlyVariableAssigns, function (Assign $assign): bool {
return array_filter($readOnlyVariableAssigns, static function (Assign $assign): bool {
$parent = $assign->getAttribute(AttributeKey::PARENT_NODE);
return ! $parent instanceof Assign;
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ private function cleanParamsFromVisibilityAndAttributes(array $params): array
$cleanParams = $this->promotedPropertyParamCleaner->cleanFromFlags($params);

// remove deep attributes to avoid bugs with nested tokens re-print
$this->simpleCallableNodeTraverser->traverseNodesWithCallable($cleanParams, function (Node $node) {
$this->simpleCallableNodeTraverser->traverseNodesWithCallable($cleanParams, static function (Node $node) {
$node->setAttributes([]);
return null;
});
Expand Down
2 changes: 1 addition & 1 deletion src/NodeManipulator/VariableManipulator.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ private function hasEncapsedStringPart(Expr $expr): bool
{
return (bool) $this->betterNodeFinder->findFirst(
$expr,
fn (Node $subNode): bool => $subNode instanceof Encapsed || $subNode instanceof EncapsedStringPart
static fn (Node $subNode): bool => $subNode instanceof Encapsed || $subNode instanceof EncapsedStringPart
);
}

Expand Down
2 changes: 1 addition & 1 deletion src/NonPhpFile/Rector/RenameClassNonPhpRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ private function renameClasses(string $newContent, array $classRenames): string
$newContent = Strings::replace(
$newContent,
$oldClassRegex,
fn (array $match): string => ($match['extra_space'] ?? '') . $newClass
static fn (array $match): string => ($match['extra_space'] ?? '') . $newClass
);
}

Expand Down
2 changes: 1 addition & 1 deletion src/PhpParser/Parser/InlineCodeParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public function stringify(Expr $expr): string
return Strings::replace(
$string,
self::VARIABLE_IN_SINGLE_QUOTED_REGEX,
fn (array $match) => $match['variable']
static fn (array $match) => $match['variable']
);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Reporting/MissingRectorRulesReporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function reportIfMissing(): ?int
{
$activeRectors = array_filter(
$this->rectors,
function (RectorInterface $rector): bool {
static function (RectorInterface $rector): bool {
if ($rector instanceof PostRectorInterface) {
return false;
}
Expand Down

0 comments on commit 20e187c

Please sign in to comment.