Repository navigation
Releases
v4.23.2
Supports Psalm 7.14 to 7.16 and keeps Psalm 7.16's star projections (Relation<*, *>) through relation calls.
Fixes
- Keep
*type arguments when a relation call is forwarded to its builder. With Psalm 7.16 aHasMany<*, User>staysHasMany<*, User>throughwhere(), scopes and other builder methods, instead of becomingHasMany<Model, User>and passing where a concrete relation is required (#2378)
/** @param HasMany<*, User> $posts */
$active = $posts->where('active', true);
-// HasMany<Model, User>
+// HasMany<*, User>- Support Psalm 7.14 and 7.15: stubs follow their changes, and
Enumerable::when()/unless()callbacks accept the value argument. Requiresvimeo/psalm^7.14.0(#2377)
Full Changelog: v4.23.1...v4.23.2
v4.23.1
Taint now flows through Stringable chains.
Fixes
- Keep the taint of a
Stringablethrough the methods whose result holds its string, such astrim(),upper(),after(),limit(),append()andtoString(). EachStringablekeeps its own taint, so a tainted call doesn't taint the same method on other strings.hash(),encrypt(),toBase64()andnumbers()drop the taint, andslug()andstripTags()remove HTML (#2374)
$name = $request->str('name');
echo $name->trim()->upper();
-// no issue
+// TaintedHtml
echo Str::of('safe')->upper();
// no issueFull Changelog: v4.23.0...v4.23.1
v4.23.0
This release targets Psalm 7.13. It reports open redirects and cookies without the secure flag, reads the session and raw database queries back from what the application stored, and trusts values Validator::make() checked against a regex.
Requirements
- Require
vimeo/psalm^7.13.1(#2373). Projects on Psalm 7.12 keep v4.22.7.
Features
- Report a user-controlled redirect target as
TaintedRedirect, and the URL syntax injected after a fixed server asTaintedUrlComponent/TaintedUrlPath, onredirect(),Redirector,ResponseFactoryand its contract (#2357)
redirect('https://example.com/' . (string) $request->input('page'));
// TaintedUrlComponent- Report a cookie made with the secure flag explicitly off as
InsecureCookie(#2357)
response()->json(['ok' => 1])->cookie('session', $token, 0, '/', null, false, true, false, 'Strict');
// InsecureCookie- Track what raw
DB/Connectionqueries store in each column, and report it where a query reads that column back (#2359)
DB::insert('INSERT INTO comments (author, body) VALUES (?, ?)', ['admin', $request->input('body')]);
$comment = DB::selectOne('SELECT author, body FROM comments');
echo (string) $comment->body;
// TaintedHtml
echo (string) $comment->author;
// no issue- Trust a value that
Validator::make()orvalidator()checked against aregexrule once the validator passes (#2358)
$validator = Validator::make(['agent' => $agent], ['agent' => ['required', 'regex:#^[a-zA-Z0-9 _.\-]+$#']]);
if ($validator->fails()) {
return;
}
echo $agent;
-// TaintedHtml
+// no issueFixes
- Read a session value back from what the application stored under its key instead of treating every session read as user input (#2357).
getOldInput()andpreviousUrl()stay user input.
$session->flash('status', 'saved');
$session->put('name', $request->input('name'));
echo (string) $session->get('status');
-// TaintedHtml
+// no issue
echo (string) $session->get('name');
// TaintedHtml- Keep the values of a
where([...])array, which Laravel binds as parameters, free ofTaintedSqlon Psalm 7.13 (#2373)
Full Changelog: v4.22.7...v4.23.0
v4.22.7
Compatibility with the upcoming Psalm 7 change to template argument keys.
Fixes
- Sanctum's default
TTokenbinding and the factoryTModelbinding keep working once Psalm keystemplate_type_extends_countandtemplate_extended_offsetsby the lowercase parent name (vimeo/psalm#14397); releases of Psalm before that change are still supported (#2372)
Full Changelog: v4.22.6...v4.22.7
v4.22.6
Console commands declared with the Laravel 13 #[Signature] attribute.
Features
- Read the command signature from the Laravel 13
#[Signature]attribute, soargument()/option()narrowing,hasArgument()/hasOption()and theInvalidConsoleArgumentName/InvalidConsoleOptionNamechecks work for commands migrated fromprotected $signature(e.g. by Rector's Laravel set). As in Laravel, the attribute overrides a$signatureproperty and is read from the concrete class only (#2371)
#[Signature('app:demo {name} {--tag=*}')]
final class Demo extends Command { /* ... */ }
$this->argument('name');
-// array<array-key, mixed>|null|scalar
+// string
foreach ($this->option('tag') as $tag) {}
-// PossiblyNullIterator, PossiblyInvalidIterator
+// array<int, string>Full Changelog: v4.22.5...v4.22.6
v4.22.5
Requires vimeo/psalm ^7.12.0, and a nullable Request::route().
Fixes
- Type
Request::route()without arguments asRoute|null: Laravel returnsnullwhen no route matched (error pages, console, queued code). Guards on it no longer report redundant checks, and an unguarded call reportsPossiblyNullReference(#2367)
$name = request()->route()?->getName();
-// RedundantConditionGivenDocblockType: Docblock-defined type Illuminate\Routing\Route for $__tmp_nullsafe__N is never null
+// string|null- Blade: stop reporting
PossiblyUndefinedGlobalVariableon$__sessionPrevious/$__contextPreviousin templates with consecutive@sessionor@contextblocks on Psalm 7.12 (#2369)
Full Changelog: v4.22.4...v4.22.5
v4.22.4
Psalm 7.11 and psalm/psalm-plugin-api 0.5.
Requirements
- Require
vimeo/psalm^7.11.0. Upgrade Psalm together with the plugin:composer u vimeo/psalm -W(#2366) - Allow
psalm/psalm-plugin-api^0.5(#2365)
Internal changes
- The Blade file hashes, shadow files and cache directory use
xxh3instead ofsha1()/md5(), so the Blade caches are rebuilt once after the upgrade (#2366)
Full Changelog: v4.22.3...v4.22.4
v4.22.3
Arrow function callbacks in migrations, on Psalm 7.10.
Requirements
- Require
vimeo/psalm^7.10.0. Upgrade Psalm together with the plugin:composer u vimeo/psalm -W(#2355)
Fixes
- Read migration columns declared in arrow function callbacks of
Schema::create(),Schema::table()andBlueprint::after()(#2350)
Schema::create('tags', fn (Blueprint $table) => $table->string('name'));
$name = Tag::first()->name;
-// UndefinedMagicPropertyFetch: the `name` column was never read
+// stringFull Changelog: v4.22.2...v4.22.3
v4.22.2
Type precision for array helpers, higher-order collection grouping and the remember_token column.
Fixes
- Type
Arr::map()andArr::mapWithKeys()results from the callback instead ofarray<array-key, mixed>(#2349)
/** @var array<string, int> $prices */
$cents = Arr::map($prices, fn (int $price, string $sku): float => $price / 100);
-// array<array-key, mixed>, then MixedReturnTypeCoercion / MixedArgumentTypeCoercion downstream
+// array<string, float>- Type the outer key of higher-order
groupByandkeyBy($users->groupBy->active) asintwhen the grouped value is abool,intor int-backed enum, like thegroupBy('active')form already does (#2344)
$byActive = $users->groupBy->active; // active: bool
-// Collection<array-key, Collection<int, User>>
+// Collection<int, Collection<int, User>>- Type the
remember_tokencolumn from$table->rememberToken()asstring|null: Laravel always creates it nullable (#2343)
$token = $user->remember_token;
-// string
+// string|nullFull Changelog: v4.22.1...v4.22.2
v4.22.1
Psalm 7.9 compatibility. Plugin v4.22.0 can crash with a TypeError on Psalm 7.9 when analyzing a nullsafe property fetch through a higher-order collection proxy ($c->map?->name), so this release requires Psalm 7.9.
Requirements
- Require
vimeo/psalm^7.9.0(was^7.7.0). Upgrade Psalm together with the plugin:composer update vimeo/psalm psalm/plugin-laravel(#2333)
Features
- Type the closure parameter of eager-load constraints in
with(),withOnly(),load()andloadMissing()(#1955)
Customer::query()->with(['vehicles' => fn ($query) => $query->where('year', '>', 2020)]);
-// MissingClosureParamType, MixedMethodCall: $query was untyped
+// $query is typed as the constrained relationFixes
- 🛡️ Propagate closure return taint through
value(),rescue(),retry(),once(),with()andDB::transaction()(#2280)
echo DB::transaction(fn () => (string) $request->input('name'));
-// no issue
+// TaintedHtml, TaintedTextWithQuotes- Type a custom caster's
get()by its native return type when it has no docblock (#2294)
// MoneyCast::get(...): Money, no docblock
return $payment->amount->format();
-// MixedReturnStatement, PossiblyNullReference, MixedMethodCall
+// no issue- Report a wrong
@returnon template-boundgroupBy()andkeyBy()receivers (@template C of Collection<...>) asInvalidReturnStatementinstead of accepting it (#2332) - Stop narrowing
getKey()tointfor the non-finalIlluminate\Foundation\Auth\Userreceiver, which can use string keys (#2293)
$key = $user->getKey();
if (\is_string($key)) { ... }
-// TypeDoesNotContainType: Type int for $key is never string
+// no issue- Type
__()andtrans()calls with amixedkey asstring(#2289)
return '"' . __($row['message']) . '"';
-// PossiblyNullOperand, PossiblyInvalidOperand
+// only MixedArgument for the mixed key remains- Stop flagging custom Eloquent builder methods returning
selfasPossiblyUnusedReturnValue(#1449) - Narrow
non-empty-stringtonon-falsy-stringinCollection::filter()without a callback, since it removes"0"(#2335)
Full Changelog: v4.22.0...v4.22.1