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

__construct(ModelRuleHelper $modelRuleHelper, ModelHelper $modelHelper)

Create a new no model make rule instance.

string
getNodeType()

Get the node type the rule checks.

array
processNode(Node $node, Scope $scope)

Report make() calls on models that the constructor could create instead.

bool
isCalledOnModel(StaticCall $call, Scope $scope)

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.

Parameters

ModelRuleHelper $modelRuleHelper
ModelHelper $modelHelper

at line 75
string getNodeType()

Get the node type the rule checks.

Return Value

string

at line 85
array processNode(Node $node, Scope $scope)

Report make() calls on models that the constructor could create instead.

Parameters

Node $node
Scope $scope

Return Value

array

at line 113
protected bool isCalledOnModel(StaticCall $call, Scope $scope)

Was the expression called on models that make() creates as their constructors do?

Parameters

StaticCall $call
Scope $scope

Return Value

bool