class NoUnnecessaryEnumerableToArrayCallsRule implements Rule

This rule checks for unnecessary calls Enumerable::toArray() that could have used all() instead. The toArray() method recursively converts all Arrayable items in the Enumerable to an array and if none of the items are Arrayable, it is unnecessary map call.

For example: collect([1, 2, 3])->toArray() could be simplified to: collect([1, 2, 3])->all()

Methods

string
getNodeType()

Get the node type the rule checks.

array
processNode(Node $node, Scope $scope)

Report toArray() calls that return the same array as all().

Details

at line 40
string getNodeType()

Get the node type the rule checks.

Return Value

string

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

Report toArray() calls that return the same array as all().

Parameters

Node $node
Scope $scope

Return Value

array