v4.18.1 moves to the stable Psalm 7.0 release and uses its template defaults to type Eloquent factories, dates and higher-order collection properties more precisely.
Requirements
- Require stable Psalm 7.0
- Default config: Psalm 7.0 no longer reports purity suggestions by default. To keep
MissingPureAnnotation,MissingAbstractPureAnnotation,MissingImmutableAnnotationandMissingInterfaceImmutableAnnotation, setsuggestPurityAnnotations="true"inpsalm.xml(#2196)
Features
- Infer the factory count from
factory(),newandcount()on the concrete factory class, somake()/create()return one model or a collection instead of both, and custom state methods stay callable aftercount()(#2192)
User::factory()->create();
-// User|Collection<int, User>
+// User
User::factory()->count(3)->admin()->create();
-// UndefinedMagicMethod: admin()
+// Collection<int, User>- Type property fetches through
HigherOrderCollectionProxy, so$collection->map->idis a collection of the property type, not the property type itself (#2182)
collect($questions)->map->id->all();
-// InvalidMethodCall: string has no method all()
+// array<int, string>- Type Eloquent
date/datetimecasts as theDate::use()class instead of alwaysIlluminate\Support\Carbon(#2004)
// AppServiceProvider: Date::use(CarbonImmutable::class);
$post->published_at;
-// Illuminate\Support\Carbon
+// Carbon\CarbonImmutable- Type
created_at/updated_atwithout a cast or@propertyas the configured date class, not the raw schemastring|null(#2163)
$notification->created_at?->toIso8601String();
-// InvalidMethodCall: string has no method toIso8601String()
+// string|null- Read Carbon
$timestampasint, and typediffForHumans()$syntax(and itsfrom,since,to,until,fromNow,toNow,agoaliases) as theCarbonInterface::DIFF_*constants, so an out-of-range int is reported (#2165)
'k:' . $date->timestamp;
-// PossiblyInvalidOperand: int|float|string
+// string- Adopt Psalm 7.0 template defaults:
ScopeisScope<TModel = Model>, andbelongsToMany()/morphToMany()/morphedByMany()return the 2-argument form. A bareextends Factorywhose model the plugin cannot resolve now reportsMissingTemplateParam(#2189)
Fixes
- Fix
Collection::first()stayingTValue|nullafter anisEmpty()early return (#2170)
if ($viewables->isEmpty()) {
return;
}
$model = $viewables->first();
-// class-string<Model>|null
+// class-string<Model>- Fix a fatal crash when a scanned facade or model class has the same name as a
useimport in its own file; the class is skipped with a warning and Psalm reports the file asParseError(#2190) - Start Blade issue locations at the first non-blank character of the line, so the reported column and highlight skip indentation (#2169)
Full Changelog: v4.18.0...v4.18.1