Skip to content

Commit

Permalink
Updated Rector to commit 83f2b16
Browse files Browse the repository at this point in the history
rectorphp/rector-src@83f2b16 [cs] add static lambda rule [closes #2514]
  • Loading branch information
TomasVotruba committed Jun 21, 2022
1 parent 3e494a7 commit 138ae66
Show file tree
Hide file tree
Showing 54 changed files with 75 additions and 75 deletions.
2 changes: 1 addition & 1 deletion packages/BetterPhpDocParser/Comment/CommentsMerger.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public function keepChildren(Node $newNode, Node $oldNode) : void
private function collectChildrenComments(Node $node) : array
{
$childrenComments = [];
$this->simpleCallableNodeTraverser->traverseNodesWithCallable($node, function (Node $node) use(&$childrenComments) {
$this->simpleCallableNodeTraverser->traverseNodesWithCallable($node, static function (Node $node) use(&$childrenComments) {
$comments = $node->getComments();
if ($comments !== []) {
$childrenComments = \array_merge($childrenComments, $comments);
Expand Down
2 changes: 1 addition & 1 deletion packages/BetterPhpDocParser/PhpDocInfo/PhpDocInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ public function getTagsByName(string $name) : array
}
$tags = $this->phpDocNode->getTags();
$name = $this->annotationNaming->normalizeName($name);
$tags = \array_filter($tags, function (PhpDocTagNode $tag) use($name) : bool {
$tags = \array_filter($tags, static function (PhpDocTagNode $tag) use($name) : bool {
return $tag->name === $name;
});
$tags = \array_values($tags);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function removeTagValueFromNode(PhpDocInfo $phpDocInfo, Node $desiredNode
{
$phpDocNode = $phpDocInfo->getPhpDocNode();
$phpDocNodeTraverser = new PhpDocNodeTraverser();
$phpDocNodeTraverser->traverseWithCallable($phpDocNode, '', function ($node) use($desiredNode, $phpDocInfo) : ?int {
$phpDocNodeTraverser->traverseWithCallable($phpDocNode, '', static function ($node) use($desiredNode, $phpDocInfo) : ?int {
if ($node instanceof PhpDocTagNode && $node->value === $desiredNode) {
$phpDocInfo->markAsChanged();
return PhpDocNodeTraverser::NODE_REMOVE;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public function findByType(PhpDocNode $phpDocNode, string $desiredType) : array
{
$phpDocNodeTraverser = new PhpDocNodeTraverser();
$foundNodes = [];
$phpDocNodeTraverser->traverseWithCallable($phpDocNode, '', function ($node) use(&$foundNodes, $desiredType) : Node {
$phpDocNodeTraverser->traverseWithCallable($phpDocNode, '', static function ($node) use(&$foundNodes, $desiredType) : Node {
if (!\is_a($node, $desiredType, \true)) {
return $node;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/Config/RectorConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public function ruleWithConfiguration(string $rectorClass, array $configuration)
Assert::isAOf($rectorClass, ConfigurableRectorInterface::class);
$services = $this->services();
// 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
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ private function getVariableUsages(Variable $variable) : array
if ($scope === null) {
return [];
}
return $this->betterNodeFinder->find((array) $scope->stmts, function (Node $node) use($variable) : bool {
return $this->betterNodeFinder->find((array) $scope->stmts, static function (Node $node) use($variable) : bool {
if (!$node instanceof Variable) {
return \false;
}
Expand Down
6 changes: 3 additions & 3 deletions packages/NodeTypeResolver/PHPStan/TypeHasher.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public function createTypeHash(Type $type) : string
}
$type = $this->normalizeObjectType($type);
// normalize iterable
$type = TypeTraverser::map($type, function (Type $currentType, callable $traverseCallback) : Type {
$type = TypeTraverser::map($type, static function (Type $currentType, callable $traverseCallback) : Type {
if (!$currentType instanceof ObjectType) {
return $traverseCallback($currentType);
}
Expand Down Expand Up @@ -75,7 +75,7 @@ private function createUnionTypeHash(UnionType $unionType) : string
}
$normalizedUnionType = clone $unionType;
// change alias to non-alias
$normalizedUnionType = TypeTraverser::map($normalizedUnionType, function (Type $type, callable $callable) : Type {
$normalizedUnionType = TypeTraverser::map($normalizedUnionType, static function (Type $type, callable $callable) : Type {
if (!$type instanceof AliasedObjectType && !$type instanceof ShortenedObjectType) {
return $callable($type);
}
Expand All @@ -85,7 +85,7 @@ private function createUnionTypeHash(UnionType $unionType) : string
}
private function normalizeObjectType(Type $type) : Type
{
return TypeTraverser::map($type, function (Type $currentType, callable $traverseCallback) : Type {
return TypeTraverser::map($type, static function (Type $currentType, callable $traverseCallback) : Type {
if ($currentType instanceof ShortenedObjectType) {
return new FullyQualifiedObjectType($currentType->getFullyQualifiedName());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ private function areArrayUnionConstantEqualTypes(Type $firstType, Type $secondTy
}
private function normalizeConstantBooleanType(Type $type) : Type
{
return TypeTraverser::map($type, function (Type $type, callable $callable) : Type {
return TypeTraverser::map($type, static function (Type $type, callable $callable) : Type {
if ($type instanceof ConstantBooleanType) {
return new BooleanType();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ private function createGenericClassStringType(array $availableTypes) : ?GenericC
*/
private function filterOutNativeClassReflections(array $classReflections) : array
{
return \array_filter($classReflections, function (ClassReflection $classReflection) : bool {
return \array_filter($classReflections, static function (ClassReflection $classReflection) : bool {
return !$classReflection->isBuiltin();
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ private function isLeftPartOfAssign(Expr $expr) : bool
if (!$parentAssign instanceof Assign) {
return \true;
}
return !(bool) $this->betterNodeFinder->findFirst($parentAssign->var, function (Node $node) use($expr) : bool {
return !(bool) $this->betterNodeFinder->findFirst($parentAssign->var, static function (Node $node) use($expr) : bool {
return $node === $expr;
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ private function shouldSkipChaoticClassMethods(ClassMethod $classMethod) : bool
}
private function hasClassMethodExprReturn(ClassMethod $classMethod) : bool
{
return (bool) $this->betterNodeFinder->findFirst((array) $classMethod->stmts, function (Node $node) : bool {
return (bool) $this->betterNodeFinder->findFirst((array) $classMethod->stmts, static function (Node $node) : bool {
if (!$node instanceof Return_) {
return \false;
}
Expand Down
2 changes: 1 addition & 1 deletion rules/CodeQuality/NodeAnalyzer/ForAnalyzer.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public function isCountValueVariableUsedInsideForStatements(For_ $for, ?Expr $ex
}
public function isArrayWithKeyValueNameUnsetted(For_ $for) : bool
{
return (bool) $this->betterNodeFinder->findFirst($for->stmts, function (Node $node) : bool {
return (bool) $this->betterNodeFinder->findFirst($for->stmts, static function (Node $node) : bool {
/** @var Node $parent */
$parent = $node->getAttribute(AttributeKey::PARENT_NODE);
if (!$parent instanceof Unset_) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ private function refactorClassMethod(ClassMethod $classMethod) : ?ClassMethod
}
private function shouldSkipExactlyReturnDateTime(ClassMethod $classMethod) : bool
{
$return = $this->betterNodeFinder->findFirstInFunctionLikeScoped($classMethod, function (Node $node) : bool {
$return = $this->betterNodeFinder->findFirstInFunctionLikeScoped($classMethod, static function (Node $node) : bool {
return $node instanceof Return_;
});
if (!$return instanceof Return_) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public function provideMinPhpVersion() : int
*/
private function matchReturnOrAssignNode(Foreach_ $foreach) : ?Node
{
return $this->foreachManipulator->matchOnlyStmt($foreach, function (Node $node) : ?Node {
return $this->foreachManipulator->matchOnlyStmt($foreach, static function (Node $node) : ?Node {
if (!$node instanceof If_) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ private function processBooleanNot(BooleanNot $booleanNot) : ?Node
}
private function processIdenticalAndNotIdentical(Identical $identical) : ?Node
{
$twoNodeMatch = $this->binaryOpManipulator->matchFirstAndSecondConditionNode($identical, function (Node $binaryOp) : bool {
$twoNodeMatch = $this->binaryOpManipulator->matchFirstAndSecondConditionNode($identical, static function (Node $binaryOp) : bool {
return $binaryOp instanceof Identical || $binaryOp instanceof NotIdentical;
}, function (Node $binaryOp) : bool {
return $this->valueResolver->isTrueOrFalse($binaryOp);
Expand Down
2 changes: 1 addition & 1 deletion rules/CodingStyle/ClassNameImport/AliasUsesResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function resolveFromNode(Node $node) : array
public function resolveFromStmts(array $stmts) : array
{
$aliasedUses = [];
$this->useImportsTraverser->traverserStmts($stmts, function (UseUse $useUse, string $name) use(&$aliasedUses) : void {
$this->useImportsTraverser->traverserStmts($stmts, static function (UseUse $useUse, string $name) use(&$aliasedUses) : void {
if ($useUse->alias === null) {
return;
}
Expand Down
2 changes: 1 addition & 1 deletion rules/CodingStyle/ClassNameImport/ShortNameResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ private function resolveFromStmtsDocBlocks(array $stmts) : array
return null;
}
$phpDocNodeTraverser = new PhpDocNodeTraverser();
$phpDocNodeTraverser->traverseWithCallable($phpDocInfo->getPhpDocNode(), '', function ($node) use(&$shortNames) {
$phpDocNodeTraverser->traverseWithCallable($phpDocInfo->getPhpDocNode(), '', static function ($node) use(&$shortNames) {
if ($node instanceof PhpDocTagNode) {
$shortName = \trim($node->name, '@');
if (StringUtils::isMatch($shortName, self::BIG_LETTER_START_REGEX)) {
Expand Down
4 changes: 2 additions & 2 deletions rules/CodingStyle/ClassNameImport/UsedImportsResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public function resolveForStmts(array $stmts) : array
$className = (string) $this->nodeNameResolver->getName($class);
$usedImports[] = new FullyQualifiedObjectType($className);
}
$this->useImportsTraverser->traverserStmts($stmts, function (UseUse $useUse, string $name) use(&$usedImports) : void {
$this->useImportsTraverser->traverserStmts($stmts, static function (UseUse $useUse, string $name) use(&$usedImports) : void {
if ($useUse->alias !== null) {
$usedImports[] = new AliasedObjectType($useUse->alias->toString(), $name);
} else {
Expand All @@ -77,7 +77,7 @@ public function resolveForStmts(array $stmts) : array
public function resolveFunctionImportsForStmts(array $stmts) : array
{
$usedFunctionImports = [];
$this->useImportsTraverser->traverserStmtsForFunctions($stmts, function (UseUse $useUse, string $name) use(&$usedFunctionImports) : void {
$this->useImportsTraverser->traverserStmtsForFunctions($stmts, static function (UseUse $useUse, string $name) use(&$usedFunctionImports) : void {
$usedFunctionImports[] = new FullyQualifiedObjectType($name);
});
return $usedFunctionImports;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public function refactor(Node $node) : ?Node
if (\is_string($aliasName)) {
$typeShortName = $aliasName;
}
$newVariableName = Strings::replace(\lcfirst($typeShortName), self::STARTS_WITH_ABBREVIATION_REGEX, function (array $matches) : string {
$newVariableName = Strings::replace(\lcfirst($typeShortName), self::STARTS_WITH_ABBREVIATION_REGEX, static function (array $matches) : string {
$output = '';
$output .= isset($matches[1]) ? \strtolower((string) $matches[1]) : '';
$output .= $matches[2] ?? '';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public function getNodeTypes() : array
public function configure(array $configuration) : void
{
Assert::allString($configuration);
$this->annotationsToConsiderForInlining = \array_map(function (string $annotation) : string {
$this->annotationsToConsiderForInlining = \array_map(static function (string $annotation) : string {
return '@' . \ltrim($annotation, '@');
}, $configuration);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public function getParts(String_ $string, array $classNames) : array
$quotedClassNames = \array_map('preg_quote', $classNames);
// @see https://regex101.com/r/8nGS0F/1
$parts = Strings::split($string->value, '#(' . \implode('|', $quotedClassNames) . ')#');
return \array_filter($parts, function (string $className) : bool {
return \array_filter($parts, static function (string $className) : bool {
return $className !== '';
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public function collectNodesByTypeAndPosition(array $assignedVariables, array $a
*/
private function sortByStart(array $nodesByTypeAndPosition) : array
{
\usort($nodesByTypeAndPosition, function (VariableNodeUse $firstVariableNodeUse, VariableNodeUse $secondVariableNodeUse) : int {
\usort($nodesByTypeAndPosition, static function (VariableNodeUse $firstVariableNodeUse, VariableNodeUse $secondVariableNodeUse) : int {
return $firstVariableNodeUse->getStartTokenPosition() <=> $secondVariableNodeUse->getStartTokenPosition();
});
return $nodesByTypeAndPosition;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,10 @@ private function getArrayItemsWithDuplicatedKey(Array_ $array) : array
private function filterItemsWithSameKey(array $arrayItemsByKeys) : array
{
/** @var ArrayItem[][] $arrayItemsByKeys */
$arrayItemsByKeys = \array_filter($arrayItemsByKeys, function (array $arrayItems) : bool {
$arrayItemsByKeys = \array_filter($arrayItemsByKeys, static function (array $arrayItems) : bool {
return \count($arrayItems) > 1;
});
return \array_filter($arrayItemsByKeys, function (array $arrayItems) : bool {
return \array_filter($arrayItemsByKeys, static function (array $arrayItems) : bool {
return \count($arrayItems) > 1;
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ private function shouldSkip(Assign $assign) : bool
if (!$variable->name instanceof Variable) {
return $this->followedByCurlyBracketAnalyzer->isFollowed($this->file, $variable);
}
return (bool) $this->betterNodeFinder->findFirstNext($assign, function (Node $node) : bool {
return (bool) $this->betterNodeFinder->findFirstNext($assign, static function (Node $node) : bool {
return $node instanceof Variable;
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ private function replaceVariablesWithPropertyFetch(StmtsAwareInterface $stmtsAwa
{
// remove assign node
unset($stmtsAware->stmts[$currentStmtsKey]);
$this->traverseNodesWithCallable($stmtsAware, function (Node $node) use($variableUsages, $propertyFetch) : ?PropertyFetch {
$this->traverseNodesWithCallable($stmtsAware, static function (Node $node) use($variableUsages, $propertyFetch) : ?PropertyFetch {
if (!\in_array($node, $variableUsages, \true)) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public function refactor(Node $node) : ?Node
$selfVariable = $this->namedVariableFactory->createVariable($node, 'self');
$expression = new Expression(new Assign($selfVariable, new Variable('this')));
$this->nodesToAddCollector->addNodeBeforeNode($expression, $node, $this->file->getSmartFileInfo());
$this->traverseNodesWithCallable($node, function (Node $subNode) use($selfVariable) : ?Closure {
$this->traverseNodesWithCallable($node, static function (Node $subNode) use($selfVariable) : ?Closure {
if (!$subNode instanceof Closure) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ private function createReflectionInstantiation(New_ $new, array $args) : ?Expr
/** @var Array_ $array */
$array = $unpackedArgs[0]->value;
$arrayItems = \array_filter($array->items);
$new->args = \array_map(function (ArrayItem $item) : Arg {
$new->args = \array_map(static function (ArrayItem $item) : Arg {
return new Arg($item->value);
}, $arrayItems);
return $new;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ private function applyArrayFilterUseBoth(array $args, Closure $closure, Variable
$key = $closure->params[1]->var;
$foreach = new Foreach_($arrayValue, $value, ['keyVar' => $key]);
$stmts = [];
$this->simpleCallableNodeTraverser->traverseNodesWithCallable($closure->stmts, function (Node $subNode) use($variable, $key, $value, &$stmts) {
$this->simpleCallableNodeTraverser->traverseNodesWithCallable($closure->stmts, static function (Node $subNode) use($variable, $key, $value, &$stmts) {
if (!$subNode instanceof Stmt) {
return null;
}
Expand Down Expand Up @@ -150,7 +150,7 @@ private function applyArrayFilterUseKey(array $args, Closure $closure, Variable
$key = $closure->params[0]->var;
$foreach = new Foreach_($funcCall, $key);
$stmts = [];
$this->simpleCallableNodeTraverser->traverseNodesWithCallable($closure->stmts, function (Node $subNode) use($variable, $key, $arrayValue, &$stmts) {
$this->simpleCallableNodeTraverser->traverseNodesWithCallable($closure->stmts, static function (Node $subNode) use($variable, $key, $arrayValue, &$stmts) {
if (!$subNode instanceof Stmt) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public function getNodeTypes() : array
*/
public function refactor(Node $node) : ?Node
{
$match = $this->betterNodeFinder->findFirst($node, function (Node $subNode) : bool {
$match = $this->betterNodeFinder->findFirst($node, static function (Node $subNode) : bool {
return $subNode instanceof Match_;
});
if (!$match instanceof Match_) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ private function refactorCoalesce(Coalesce $coalesce, ?Assign $assign)
}
private function hasThrowInAssignExpr(Assign $assign) : bool
{
return (bool) $this->betterNodeFinder->findFirst($assign->expr, function (Node $node) : bool {
return (bool) $this->betterNodeFinder->findFirst($assign->expr, static function (Node $node) : bool {
return $node instanceof Throw_;
});
}
Expand Down
2 changes: 1 addition & 1 deletion rules/EarlyReturn/NodeFactory/InvertedIfFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public function createFromConditions(If_ $if, array $conditions, Return_ $return
}
private function getNextReturnExpr(If_ $if) : ?Node
{
return $this->betterNodeFinder->findFirstNext($if, function (Node $node) : bool {
return $this->betterNodeFinder->findFirstNext($if, static function (Node $node) : bool {
return $node instanceof Return_ && $node->expr instanceof Expr;
});
}
Expand Down
4 changes: 2 additions & 2 deletions rules/Naming/Naming/UseImportsResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function resolveForNode(Node $node) : array
if (!$namespace instanceof Node) {
return [];
}
return \array_filter($namespace->stmts, function (Stmt $stmt) : bool {
return \array_filter($namespace->stmts, static function (Stmt $stmt) : bool {
return $stmt instanceof Use_ || $stmt instanceof GroupUse;
});
}
Expand All @@ -43,7 +43,7 @@ public function resolveBareUsesForNode(Node $node) : array
if (!$namespace instanceof Node) {
return [];
}
return \array_filter($namespace->stmts, function (Stmt $stmt) : bool {
return \array_filter($namespace->stmts, static function (Stmt $stmt) : bool {
return $stmt instanceof Use_;
});
}
Expand Down
Loading

0 comments on commit 138ae66

Please sign in to comment.