private function checkForbiddenOrDiscouragedRule(RuleInterface $rule, NodeInterface $node): ?ViolationInterface
    {
        $errors = array();

        foreach ($node->getTokens() as $token) {
            if (!$this->checkTokenForForbiddenOrDiscouragedRule($rule, $token) &&
                !in_array($token, $errors)) {
                $errors[] = $token;
            }
        }

        if (count($errors)) {
            $type = $rule->getType() === RuleInterface::TYPE_FORBIDDEN ?
                    ViolationInterface::TYPE_ERROR :
                    ViolationInterface::TYPE_WARNING
            ;

            return new Violation($node, $rule, $errors, $type);
        }

        return null;
    }