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
3 changes: 3 additions & 0 deletions config/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ parameters:
autoload_paths: []
rector_recipe: []

# lower for performance; higher to prevent bugs with fluent interfaces like https://github.com/rectorphp/rector/issues/1646, or https://github.com/rectorphp/rector/issues/2444
nested_chain_method_call_limit: 15

# importing FQN names
auto_import_names: false
# e.g. import \DateTime
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,6 @@
*/
final class RemoveDeepChainMethodCallNodeVisitor extends NodeVisitorAbstract
{
/**
* @warning might cause bugs with fluent interfaces like https://github.com/rectorphp/rector/issues/1646
* @var int
*/
private const NESTED_CHAIN_METHOD_CALL_LIMIT = 15;

/**
* @var BetterNodeFinder
*/
Expand All @@ -33,9 +27,15 @@ final class RemoveDeepChainMethodCallNodeVisitor extends NodeVisitorAbstract
*/
private $nodeToRemove;

public function __construct(BetterNodeFinder $betterNodeFinder)
/**
* @var int
*/
private $nestedChainMethodCallLimit;

public function __construct(BetterNodeFinder $betterNodeFinder, int $nestedChainMethodCallLimit)
{
$this->betterNodeFinder = $betterNodeFinder;
$this->nestedChainMethodCallLimit = $nestedChainMethodCallLimit;
}

/**
Expand All @@ -49,7 +49,7 @@ public function enterNode(Node $node)

if ($node->expr instanceof MethodCall && $node->expr->var instanceof MethodCall) {
$nestedChainMethodCalls = $this->betterNodeFinder->findInstanceOf([$node->expr], MethodCall::class);
if (count($nestedChainMethodCalls) > self::NESTED_CHAIN_METHOD_CALL_LIMIT) {
if (count($nestedChainMethodCalls) > $this->nestedChainMethodCallLimit) {
$this->nodeToRemove = $node;

return NodeTraverser::DONT_TRAVERSE_CHILDREN;
Expand Down