packagist psalm/plugin-laravel v3.18.0

one hour ago

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, SerializedQueuedModel and UnknownModelAttribute now run by default: errors at errorLevel 1 to 4, info above (#2214)

Features

  • Infer the factory count from factory(), new and count(), so make()/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 in with(), load() and loadMissing(), 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() and withTimestamps() columns in BelongsToMany pivot shapes, using() custom pivots included (#1951, #1992, #2008, #2094)
  • Narrow app(), make() and $app[...] over unions of string literals, and infer Manager::driver() as the union of the create*Driver() return types when the driver name is not a literal (#1802, #1743)
  • Type Eloquent date/datetime casts and untyped created_at/updated_at as the Date::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 for argument()/option() narrowing and the console name checks (#2371)
  • Add psalm-laravel analyze --plugin-option=KEY=VALUE to override a plugin setting for one run (#1709)

🛡️ Taint analysis

  • Add callable sinks 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=truncate empties the table (GHSA-5wcm-3v2w-8362) (#2388)
 $query->with((string) $request->input('include'));
+// TaintedCallable
  • Add TaintedSql sinks for raw(), insertUsing(), insertOrIgnoreUsing() and rawValue() on relations, follow taint into driver methods behind Manager::driver(), and report taint reaching an inherited job constructor through parent::dispatch() (#1739, #1743, #1967)
  • Stop reporting TaintedHeader for mail display names and subjects; address arguments stay sinks (#1960)

Fixes

Eloquent and migrations:

  • Resolve dynamic where{Column}() from migration columns on models without @property docblocks, and accept any value in it as where() does (#1934, #2113)
  • Resolve Builder passthru methods (exists(), toSql(), insert(), raw()) on relations, #[UseEloquentBuilder] inherited from a parent class or trait, and the custom builder from Model::with() (#1739, #2287, #1689)
  • Check UnknownModelAttribute on builder and relation creation calls, report unparsed :columns suffixes in UndefinedModelRelation, 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 and foreignUuidFor()/foreignUlidFor() (#2350, #1691, #2288, #2284)
  • Type a custom caster's get() by its native return type, remember_token as string|null, and Carbon $timestamp as int (#2294, #2343, #2165)

Collections and support:

  • Match Collection, Eloquent\Collection and paginator return types to the runtime (random($n), max()/min(), flatMap() keys, sum(), flip(), findOrFail([...])), and widen prepend()/unshift()/add()/splice()/getOrPut() writes (#1898, #1915, #1922, #1891, #2114)
  • Keep Collection::first() non-null after an isEmpty() early return, keep TValue with a Closure default, and narrow filter()/reject() from a class-typed callback (#2170, #2283, #1913, #1916, #2335)
  • Type Arr::map()/Arr::mapWithKeys() from the callback, __()/trans() with a mixed key as string, and env() closure defaults as the closure result (#2349, #2289, #2272, #2273)
  • Type Request::route() without arguments as Route|null, and stop narrowing getKey() to int on Illuminate\Foundation\Auth\User (#2367, #2293)

Facades:

  • Register config('app.aliases') aliases with class_alias(), so an alias is the target class (enum cases, \Eloquent as a Model). Classes that only the old stubs extended may now report ClassMustBeFinal (#2133)
  • Report unknown calls on stubbed facades again, resolve facade macros with a custom aliases list, macros on Schema\Builder/Connection through Schema/DB, Http facade 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 use import in its own file, and print plugin warnings to STDERR under --no-progress (#2190, #2274)

Full Changelog: v3.17.0...v3.18.0

Don't miss a new plugin-laravel release

NewReleases is sending notifications on new releases.