Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

namespace Rector\Tests\Php81\Rector\Array_\ArrayToFirstClassCallableRector\Fixture;

final class SkipOnParam
{
public function size()
{
}

public function run(array $callback = [SkipOnParam::class, 'size'])
{
}
}
4 changes: 4 additions & 0 deletions rules/Php81/Rector/Array_/ArrayToFirstClassCallableRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@ public function refactor(Node $node): StaticCall|MethodCall|null
return null;
}

if ($node->getAttribute(AttributeKey::IS_PARAM_DEFAULT)) {
return null;
}

$args = [new VariadicPlaceholder()];
if ($callerExpr instanceof ClassConstFetch) {
$type = $this->getType($callerExpr->class);
Expand Down
2 changes: 2 additions & 0 deletions src/DependencyInjection/LazyContainerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@
use Rector\PhpParser\NodeVisitor\ContextNodeVisitor;
use Rector\PhpParser\NodeVisitor\GlobalVariableNodeVisitor;
use Rector\PhpParser\NodeVisitor\NameNodeVisitor;
use Rector\PhpParser\NodeVisitor\ParamDefaultNodeVisitor;
use Rector\PhpParser\NodeVisitor\PhpVersionConditionNodeVisitor;
use Rector\PhpParser\NodeVisitor\PropertyOrClassConstDefaultNodeVisitor;
use Rector\PhpParser\NodeVisitor\StaticVariableNodeVisitor;
Expand Down Expand Up @@ -253,6 +254,7 @@ final class LazyContainerFactory
NameNodeVisitor::class,
StaticVariableNodeVisitor::class,
PropertyOrClassConstDefaultNodeVisitor::class,
ParamDefaultNodeVisitor::class,
ClassConstFetchNodeVisitor::class,
];

Expand Down
5 changes: 5 additions & 0 deletions src/NodeTypeResolver/Node/AttributeKey.php
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,11 @@ final class AttributeKey
*/
public const IS_PARAM_VAR = 'is_param_var';

/**
* @var string
*/
public const IS_PARAM_DEFAULT = 'is_param_default';

/**
* @var string
*/
Expand Down
35 changes: 35 additions & 0 deletions src/PhpParser/NodeVisitor/ParamDefaultNodeVisitor.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

declare(strict_types=1);

namespace Rector\PhpParser\NodeVisitor;

use PhpParser\Node;
use PhpParser\Node\Expr;
use PhpParser\Node\Param;
use PhpParser\NodeVisitorAbstract;
use Rector\Contract\PhpParser\DecoratingNodeVisitorInterface;
use Rector\NodeTypeResolver\Node\AttributeKey;
use Rector\PhpParser\NodeTraverser\SimpleNodeTraverser;

final class ParamDefaultNodeVisitor extends NodeVisitorAbstract implements DecoratingNodeVisitorInterface
{
public function enterNode(Node $node): ?Node
{
if (! $node instanceof Param) {
return null;
}

if (! $node->default instanceof Expr) {
return null;
}

SimpleNodeTraverser::decorateWithAttributeValue(
$node->default,
AttributeKey::IS_PARAM_DEFAULT,
true
);

return null;
}
}