matcherDefinitions = $matcherDefinitions; // newNumberOfArguments must exist in all matcherDefinitions $this->validateMatcherDefinitions(['newNumberOfArguments']); } /** * Called by PhpParser. * Test for "public function like($arg1, $arg2, $arg3) {}" (weak match) * Test for "->like($arg1, $arg2, $arg3); (weak match) */ public function enterNode(Node $node): null { if ($this->isFileIgnored($node) || $this->isLineIgnored($node)) { return null; } // Match method name of a class, must be public, wouldn't make sense as interface if protected/private if ($node instanceof ClassMethod && array_key_exists($node->name->name, $this->matcherDefinitions) && $node->flags & Modifiers::PUBLIC // public && ($node->flags & Modifiers::STATIC) !== Modifiers::STATIC // not static ) { $methodName = $node->name->name; $numberOfUsedArguments = 0; if (is_array($node->params ?? null)) { $numberOfUsedArguments = count($node->params); } $numberOfAllowedArguments = $this->matcherDefinitions[$methodName]['newNumberOfArguments']; if ($numberOfUsedArguments > $numberOfAllowedArguments) { $this->matches[] = [ 'restFiles' => $this->matcherDefinitions[$methodName]['restFiles'], 'line' => $node->getAttribute('startLine'), 'message' => 'Implementation of dropped interface argument for method "' . $methodName . '()"', 'indicator' => 'weak', ]; } } // Match method call (not static) with number of arguments if ($node instanceof MethodCall && $node->name instanceof Identifier && array_key_exists($node->name->name, $this->matcherDefinitions) ) { $methodName = $node->name->name; $numberOfUsedArguments = 0; if (is_array($node->args ?? null)) { $numberOfUsedArguments = count($node->args); } // @todo: Test for argument unpacking $numberOfAllowedArguments = $this->matcherDefinitions[$methodName]['newNumberOfArguments']; if ($numberOfUsedArguments > $numberOfAllowedArguments) { $this->matches[] = [ 'restFiles' => $this->matcherDefinitions[$methodName]['restFiles'], 'line' => $node->getAttribute('startLine'), 'message' => 'Call to interface method "' . $methodName . '()"', 'indicator' => 'weak', ]; } } return null; } }