Combine collection predicates (ARCH7077)
Esta página aún no está disponible en tu idioma.
Key php.performance.combine-collection-predicates · Severity info · Category performance
Consecutive filter calls, or count() > 0 for an emptiness check, walk the collection multiple times. Fuse the predicates into one pass and use isNotEmpty().
Incorrect
Section titled “Incorrect”<?php$active = collect($users) ->filter(fn ($u) => $u->active) ->filter(fn ($u) => $u->age >= 18);
if ($active->count() > 0) { notify($active);}Correct
Section titled “Correct”<?php$active = collect($users) ->filter(fn ($u) => $u->active && $u->age >= 18);
if ($active->isNotEmpty()) { notify($active);}Fuse consecutive filters into a single predicate and use isNotEmpty() for emptiness checks.