v3.18.0 sharpens Eloquent, factory, collection and facade inference, turns four runtime-failure checks on by default, and adds taint sinks for request-chosen relation names. It requires Psalm 6.21.1.
Requirements
- Require
vimeo/psalm^6.21.1(was^6.16.1). Older Psalm 6 releases crash while scanning the plugin's stubs. Upgrade both together:composer update vimeo/psalm psalm/plugin-laravel -W - Support laravel/ai 1.x for the LLM prompt sinks and response sources; 0.x is no longer covered (#1588, #1765)
Rules enabled by default
MissingView,UnconfiguredFilesystemDisk,SerializedQueuedModelandUnknownModelAttributenow run by default: errors aterrorLevel1 to 4,infoabove (#2214)
Features
- Infer the factory count from
factory(),newandcount(), somake()/create()return one model or a collection instead of both (#2192, #2317)
User::factory()->create();
-// User|Collection<int, User>
+// User- Type
has{Relation}()/for{Relation}()on Eloquent factories (#2219)
$user = User::factory()->hasLinks(2)->create();
-// UndefinedMagicMethod: Magic method Database\Factories\UserFactory::haslinks does not exist
+// User- Type the closure parameter of
whereHas()and the other relation-query callbacks, and of eager-load constraints inwith(),load()andloadMissing(), as the related model's builder, custom builders included (#1791, #2110, #1955)
Customer::query()->whereHas('vehicles', fn ($q) => $q->whereElectric());
-// MixedMethodCall
+// $q is VehicleBuilder- Type
withPivot()andwithTimestamps()columns inBelongsToManypivot shapes,using()custom pivots included (#1951, #1992, #2008, #2094) - Narrow
app(),make()and$app[...]over unions of string literals, and inferManager::driver()as the union of thecreate*Driver()return types when the driver name is not a literal (#1802, #1743) - Type Eloquent
date/datetimecasts and untypedcreated_at/updated_atas theDate::use()class (#2004, #2163)
// AppServiceProvider: Date::use(CarbonImmutable::class);
$post->published_at;
-// Illuminate\Support\Carbon
+// Carbon\CarbonImmutable- Read the command signature from the Laravel 13
#[Signature]attribute forargument()/option()narrowing and the console name checks (#2371) - Add
psalm-laravel analyze --plugin-option=KEY=VALUEto override a plugin setting for one run (#1709)
🛡️ Taint analysis
- Add
callablesinks to Eloquent relation-name parameters (with(),load(),whereHas(),withCount()and the rest of the eager-loading, existence and aggregate families): a name that is not a relation runs a Builder method, so?include=truncateempties the table (GHSA-5wcm-3v2w-8362) (#2388)
$query->with((string) $request->input('include'));
+// TaintedCallable- Add
TaintedSqlsinks forraw(),insertUsing(),insertOrIgnoreUsing()andrawValue()on relations, follow taint into driver methods behindManager::driver(), and report taint reaching an inherited job constructor throughparent::dispatch()(#1739, #1743, #1967) - Stop reporting
TaintedHeaderfor mail display names and subjects; address arguments stay sinks (#1960)
Fixes
Eloquent and migrations:
- Resolve dynamic
where{Column}()from migration columns on models without@propertydocblocks, and accept any value in it aswhere()does (#1934, #2113) - Resolve
Builderpassthru methods (exists(),toSql(),insert(),raw()) on relations,#[UseEloquentBuilder]inherited from a parent class or trait, and the custom builder fromModel::with()(#1739, #2287, #1689) - Check
UnknownModelAttributeon builder and relation creation calls, report unparsed:columnssuffixes inUndefinedModelRelation, and stop reporting relations defined on a model subclass (#1953, #1949, #1984, #2220) - Read migration columns from arrow function callbacks, class-constant column names, variadic
dropColumn(),morphUsingUuids()/morphUsingUlids()morph keys andforeignUuidFor()/foreignUlidFor()(#2350, #1691, #2288, #2284) - Type a custom caster's
get()by its native return type,remember_tokenasstring|null, and Carbon$timestampasint(#2294, #2343, #2165)
Collections and support:
- Match
Collection,Eloquent\Collectionand paginator return types to the runtime (random($n),max()/min(),flatMap()keys,sum(),flip(),findOrFail([...])), and widenprepend()/unshift()/add()/splice()/getOrPut()writes (#1898, #1915, #1922, #1891, #2114) - Keep
Collection::first()non-null after anisEmpty()early return, keepTValuewith a Closure default, and narrowfilter()/reject()from a class-typed callback (#2170, #2283, #1913, #1916, #2335) - Type
Arr::map()/Arr::mapWithKeys()from the callback,__()/trans()with amixedkey asstring, andenv()closure defaults as the closure result (#2349, #2289, #2272, #2273) - Type
Request::route()without arguments asRoute|null, and stop narrowinggetKey()tointonIlluminate\Foundation\Auth\User(#2367, #2293)
Facades:
- Register
config('app.aliases')aliases withclass_alias(), so an alias is the target class (enum cases,\Eloquentas aModel). Classes that only the old stubs extended may now reportClassMustBeFinal(#2133) - Report unknown calls on stubbed facades again, resolve facade macros with a custom
aliaseslist, macros onSchema\Builder/ConnectionthroughSchema/DB,Httpfacade calls, and package facades that forward through__call(#2270, #2275, #2282, #2232, #2138, #2139) - Fix a fatal crash when a scanned class has the same name as a
useimport in its own file, and print plugin warnings to STDERR under--no-progress(#2190, #2274)
Full Changelog: v3.17.0...v3.18.0