From 6be83258a6a3af41792c1bd9dfea7b6419d60b84 Mon Sep 17 00:00:00 2001 From: TomasVotruba Date: Sun, 5 Jan 2020 00:16:49 +0100 Subject: [PATCH] make nested chain call remove configurable --- config/config.yaml | 3 +++ .../RemoveDeepChainMethodCallNodeVisitor.php | 16 ++++++++-------- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/config/config.yaml b/config/config.yaml index fea3a09652e1..e61519c1f3cd 100644 --- a/config/config.yaml +++ b/config/config.yaml @@ -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 diff --git a/packages/NodeTypeResolver/src/PHPStan/Scope/NodeVisitor/RemoveDeepChainMethodCallNodeVisitor.php b/packages/NodeTypeResolver/src/PHPStan/Scope/NodeVisitor/RemoveDeepChainMethodCallNodeVisitor.php index de0a2977bc00..bf43d069b8ed 100644 --- a/packages/NodeTypeResolver/src/PHPStan/Scope/NodeVisitor/RemoveDeepChainMethodCallNodeVisitor.php +++ b/packages/NodeTypeResolver/src/PHPStan/Scope/NodeVisitor/RemoveDeepChainMethodCallNodeVisitor.php @@ -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 */ @@ -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; } /** @@ -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;