@param mixed              $value
@param RuleInterface|null $next

@return RuleInterface

@SuppressWarnings(PHPMD.ElseExpression)
339030
protected static function equals($value, RuleInterface $next = null): RuleInterface
    {
        if ($value === null) {
            $rule = new IsNull();
        } elseif ($value instanceof DateTimeInterface) {
            $rule = new DateTimeEquals($value);
        } else {
            $rule = new ScalarEquals($value);
        }

        return $next === null ? $rule : new AndOperator(static::equals($value), $next);
    }
277057
public function handleField(FieldValue $value, Closure $next): FieldValue
    {
        $resolver = $value->getResolver();

        return $next(
            $value->setResolver(
                function (Model $parent, array $args, GraphQLContext $context, ResolveInfo $resolveInfo) use ($resolver): Deferred {
                    $loader = BatchLoader::instance(
                        RelationBatchLoader::class,
                        $resolveInfo->path,
                        [
                            'relationName' => $this->directiveArgValue('relation', $this->definitionNode->name->value),
                            'args' => $args,
                            'scopes' => $this->directiveArgValue('scopes', []),
                            'resolveInfo' => $resolveInfo,
                        ]
                    );

                    return new Deferred(function () use ($loader, $resolver, $parent, $args, $context, $resolveInfo) {
                        return $loader
                            ->load(
                                $parent->getKey(),
                                ['parent' => $parent]
                            )->then(
                                function () use ($resolver, $parent, $args, $context, $resolveInfo) {
                                    return $resolver($parent, $args, $context, $resolveInfo);
                                }
                            );
                    });
                }
            )
        );
    }
726675
public function ruleValue($value = null)
    {
        if (\func_num_args() > 0) {
            if (null !== $value && $this->validateValue($value)) {
                $this->value = $value;
                $this->updateBound();

                return true;
            }
            return false;
        }
        return $this->value;
    }
812756
public function transform($value)
    {
        if (null === $value) {
            return null;
        }

        if (!$value instanceof APILocation) {
            throw new TransformationFailedException('Expected a ' . APILocation::class . ' object.');
        }

        return $value->id;
    }
999633
public function transform($value)
    {
        if (null === $value) {
            return null;
        }

        if (!$value instanceof APIRole) {
            throw new TransformationFailedException('Expected a ' . APIRole::class . ' object.');
        }

        return $value->id;
    }
1239390
protected static function isInt(RuleInterface $next = null): RuleInterface
    {
        return $next === null ? new AsInt() : new AndOperator(new AsInt(), $next);
    }
793226
public static function existAll(string $tableName, string $primaryName, RuleInterface $next = null): RuleInterface
    {
        $primary = new ExistInDbTableMultipleWithDoctrineRule($tableName, $primaryName);

        return $next === null ? $primary : new AndOperator($primary, $next);
    }
1057956
public static function usersRelationship(RuleInterface $next = null): RuleInterface
    {
        $readableAll = static::stringArrayToIntArray(static::readableAll(UsersApi::class, $next));

        return self::toManyRelationship(UserSchema::TYPE, $readableAll);
    }
121146
public function handleField(FieldValue $value, Closure $next): FieldValue
    {
        $previousResolver = $value->getResolver();

        return $next(
            $value->setResolver(
                function ($root, array $args, GraphQLContext $context, ResolveInfo $resolveInfo) use ($previousResolver) {
                    $gate = app(Gate::class);
                    $gateArguments = $this->getGateArguments();

                    if ($id = $args['id'] ?? null) {
                        /** @var \Illuminate\Database\Eloquent\Model $modelClass */
                        $modelClass = $this->getModelClass();

                        $gateArguments[0] = $modelClass::findOrFail($id);
                    }

                    $this->getAbilities()->each(
                        function (string $ability) use ($context, $gate, $gateArguments): void {
                            $this->authorize($context->user(), $gate, $ability, $gateArguments);
                        }
                    );

                    return call_user_func_array($previousResolver, func_get_args());
                }
            )
        );
    }
993563
public static function readableAll(string $apiClass, RuleInterface $next = null): RuleInterface
    {
        $primary = new AreReadableViaApiRule($apiClass);

        return $next === null ? $primary : new AndOperator($primary, $next);
    }
433286
public static function roleRelationship(RuleInterface $next = null): RuleInterface
    {
        return self::toOneRelationship(RoleSchema::TYPE, static::roleId($next));
    }
1298542
protected static function between($lowerLimit, $upperLimit, RuleInterface $next = null): RuleInterface
    {
        $areLimitsDates = $lowerLimit instanceof DateTimeInterface && $upperLimit instanceof DateTimeInterface;

        return $next === null ?
            ($areLimitsDates ?
                new DateTimeBetween($lowerLimit, $upperLimit) : new NumericBetween($lowerLimit, $upperLimit)) :
            new AndOperator(static::between($lowerLimit, $upperLimit), $next);
    }
415537
public function wrap($value = null)
    {
        $exceptionFactory   = new ExceptionFactory($this->presenter);
        $wrappedObject      = new WrappedObject($value, $this->presenter);
        $caller             = new Caller($wrappedObject, $this->example, $this->dispatcher, $exceptionFactory, $this);
        $arrayAccess        = new SubjectWithArrayAccess($caller, $this->presenter, $this->dispatcher);
        $expectationFactory = new ExpectationFactory($this->example, $this->dispatcher, $this->matchers);

        return new Subject(
            $value, $this, $wrappedObject, $caller, $arrayAccess, $expectationFactory
        );
    }
340655
public static function asJsonApiDateTime(RuleInterface $next = null): RuleInterface
    {
        return self::stringToDateTime(DateTime::JSON_API_FORMAT, $next);
    }
563334
protected static function stringToDateTime(string $format, RuleInterface $next = null): RuleInterface
    {
        return $next === null ? new StringToDateTime($format) : new AndOperator(new StringToDateTime($format), $next);
    }
1138835
public function filter($value)
    {
        if (null === $value) {
            return null;
        }
        $this->checkValueIsValidOrThrowException($value);
        $matcher = key($value);
        $this->validateMatcherOrThrowException($matcher);
        $this->validateValueOrThrowException($value[$matcher]);

        return new Condition($matcher, $value[$matcher]);
    }
1255373
public function handleField(FieldValue $value, Closure $next): FieldValue
    {
        $middleware = $this->getQualifiedMiddlewareNames(
            $this->directiveArgValue('checks')
        );
        $resolver = $value->getResolver();

        return $next(
            $value->setResolver(
                function ($root, array $args, GraphQLContext $context, ResolveInfo $resolveInfo) use ($resolver, $middleware) {
                    return $this->pipeline
                        ->send($context->request())
                        ->through($middleware)
                        ->then(function (Request $request) use ($resolver, $root, $args, $resolveInfo) {
                            return $resolver(
                                $root,
                                $args,
                                $this->createsContext->generate($request),
                                $resolveInfo
                            );
                        });
                }
            )
        );
    }