NoModelMakeRule
class NoModelMakeRule implements Rule
Catches inefficient instantiation of models using Model::make().
For example: User::make()
It is functionally equivalent to simply use the constructor: new User()
Unlike upstream, the rule reports only models whose construction it can show is unchanged. make() also builds the model's query, whose global scopes can change the model it makes (an extend() calling withAttributes()), and pins the model to the query's connection, while the constructor leaves a default connection to resolve later. So it reports plain models with a fixed connection, made on an exact class.
Constants
| private CONSTRUCTION_METHODS |
The model methods, besides its query's, that make() runs differently from the constructor. |
Methods
Create a new no model make rule instance.
Get the node type the rule checks.
Report make() calls on models that the constructor could create instead.
Was the expression called on models that make() creates as their constructors do?
Details
at line 66
__construct(ModelRuleHelper $modelRuleHelper, ModelHelper $modelHelper)
Create a new no model make rule instance.
at line 75
string
getNodeType()
Get the node type the rule checks.
at line 85
array
processNode(Node $node, Scope $scope)
Report make() calls on models that the constructor could create instead.
at line 113
protected bool
isCalledOnModel(StaticCall $call, Scope $scope)
Was the expression called on models that make() creates as their constructors do?