Find the best Rector rule to solve your problem. Searching through 671 rules.
Found 3 rules:
Use the base collection methods instead of their aliases.
use Illuminate\Support\Collection;
$collection = new Collection([0, 1, null, -1]);
-$collection->average();
-$collection->some(fn (?int $number): bool => is_null($number));
+$collection->avg();
+$collection->contains(fn (?int $number): bool => is_null($number));
Avoid negated conditionals in filter()
by using reject()
, or vice versa.
use Illuminate\Support\Collection;
$collection = new Collection([0, 1, null, -1]);
-$collection->filter(fn (?int $number): bool => ! is_null($number));
-$collection->filter(fn (?int $number): bool => ! $number);
-$collection->reject(fn (?int $number) => ! $number > 0);
+$collection->reject(fn (?int $number): bool => is_null($number)); // Avoid negation
+$collection->reject(fn (?int $number): bool => (bool) $number); // Explicitly cast
+$collection->filter(fn (?int $number): bool => $number > 0); // Adds return type
Convert negated calls to contains
to doesntContain
, or vice versa.
use Illuminate\Support\Collection;
$collection = new Collection([0, 1, null, -1]);
-! $collection->contains(fn (?int $number): bool => is_null($number));
-! $collection->doesntContain(fn (?int $number) => $number > 0);
+$collection->doesntContain(fn (?int $number): bool => is_null($number));
+$collection->contains(fn (?int $number) => $number > 0);