NoUnnecessaryCollectionCallRule
class NoUnnecessaryCollectionCallRule implements Rule
This rule checks for unnecessary heavy operations on the Collection class that could have instead been performed on the Builder class.
For example: User::all()->count() could be simplified to: User::count()
In addition, this code: User::whereStatus('active')->get()->pluck('id') could be simplified to: User::whereStatus('active')->pluck('id')
Constants
protected RISKY_METHODS |
The method names that can be applied on a Collection, but should be applied on a Builder. |
protected RISKY_PARAM_METHODS |
The method names that can be applied on a Collection, but should in some cases be applied
on a builder depending on what parameter is passed to the method. |
Properties
protected string[] | $shouldHandle | ||
protected ReflectionProvider | $reflectionProvider | ||
protected ModelPropertyExtension | $propertyExtension |
Methods
NoRedundantCollectionCallRule constructor.
No description
No description
Determines whether the first argument is a string and references a database column.
Returns whether the method call is a call on a builder instance.
Returns whether the method is one of the risky methods.
Returns whether the method might be a risky method depending on the parameters passed.
Returns whether its argument is some builder instance.
Returns whether the Expr was not called on a Collection instance.
Formats the error.
Details
at line 103
__construct(ReflectionProvider $reflectionProvider, ModelPropertyExtension $propertyExtension, array $onlyMethods, array $excludeMethods)
NoRedundantCollectionCallRule constructor.
at line 139
string
getNodeType()
No description
at line 149
array
processNode(Node $node, Scope $scope)
No description
at line 226
protected bool
firstArgIsDatabaseColumn(StaticCall|MethodCall $node, Scope $scope)
Determines whether the first argument is a string and references a database column.
at line 281
protected bool
callIsQuery(Expr $call, Scope $scope)
Returns whether the method call is a call on a builder instance.
at line 310
protected bool
isRiskyMethod(Identifier $name)
Returns whether the method is one of the risky methods.
at line 321
protected bool
isRiskyParamMethod(Identifier $name)
Returns whether the method might be a risky method depending on the parameters passed.
at line 332
protected bool
isBuilder(Type $type)
Returns whether its argument is some builder instance.
at line 346
protected bool
isCalledOnCollection(Expr $expr, Scope $scope)
Returns whether the Expr was not called on a Collection instance.
at line 359
protected string
formatError(string $method_name)
Formats the error.