Strict Collection Creation

I like to write strictly typed PHP, or at least as much as possible. Primarily this boils down to using PHPStan . One aspect where I find this challenging is Laravel Collections . Specifically creating single-type Collections. For example, a WidgetCollection should guarantee that the collection only ever contains instances of Widget : /** @extends \Illuminate\Support\Collection< Widget > */ class…