From f4272c1d54aa1f0c1985ae5d0b13ce6afc2ad846 Mon Sep 17 00:00:00 2001 From: agis Date: Fri, 11 Sep 2026 14:55:03 +0700 Subject: [PATCH] fix(collection): widen filter/reject to be compatible with Laravel 13 Collection The custom Collection overrides `filter(?Closure $callback = null)` and `reject($callback)` with signatures narrower than the base Collection. Under the Laravel 13 upgrade the base becomes `filter(?callable $callback = null)` and `reject($callback = true)`, which makes these overrides fatal at class load: PHP LSP forbids a child from narrowing a parameter type or making an optional parameter required. Widen both to the least-restrictive form compatible with BOTH the current 4.2-era base (`filter(Closure)`, `reject($callback)`) and the Laravel 13 base: - filter: drop the parameter type entirely. PHP does not accept `callable` as a widening of `Closure`, so untyped (mixed) is the only type that is a valid override against both bases. - reject: add the `= true` default. Method bodies are unchanged (they already implement the value+key filter semantics), so behaviour is identical on both bases. This lets the package be merged and deployed independently of the framework upgrade. Co-Authored-By: Claude Opus 4.8 (1M context) --- src/Laravel/Collection.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/Laravel/Collection.php b/src/Laravel/Collection.php index 1bbb981..37f9dc6 100644 --- a/src/Laravel/Collection.php +++ b/src/Laravel/Collection.php @@ -2,13 +2,12 @@ namespace Spatie\BladeX\Laravel; -use \Closure; use Illuminate\Support\Collection as L4Collection; class Collection extends L4Collection { #[\Override] - public function filter(?Closure $callback = null) + public function filter($callback = null) { if ($callback) { // return new static(Arr::where($this->items, $callback)); @@ -68,7 +67,7 @@ public function unique($key = null, $strict = false) } #[\Override] - public function reject($callback) + public function reject($callback = true) { $useAsCallable = $this->useAsCallable($callback);