Skip to content

[php 8.4] [type-declaration] Add AddArrayAnyAllClosureParamTypeRector and NarrowArrayAnyAllNullableParamTypeRector#8049

Merged
TomasVotruba merged 1 commit into
mainfrom
tv-array-any-all-closure-rule
Jun 19, 2026
Merged

[php 8.4] [type-declaration] Add AddArrayAnyAllClosureParamTypeRector and NarrowArrayAnyAllNullableParamTypeRector#8049
TomasVotruba merged 1 commit into
mainfrom
tv-array-any-all-closure-rule

Conversation

@TomasVotruba

@TomasVotruba TomasVotruba commented Jun 19, 2026

Copy link
Copy Markdown
Member

Two new PHP 8.4 type-declaration rules for array_any()/array_all() (and friends) closure params.

AddArrayAnyAllClosureParamTypeRector

Adds a type to an untyped closure param, based on the array item type.

 /** @var string[] $items */
-array_any($items, fn ($item): bool => $item !== '');
+array_any($items, fn (string $item): bool => $item !== '');

Handles array_any(), array_all(). Only fills a param that has no type yet.


NarrowArrayAnyAllNullableParamTypeRector

Narrows an already nullable closure param to the non-nullable array item type.

 /** @var string[] $items */
-array_any($items, fn (?string $item): bool => $item !== '');
+array_any($items, fn (string $item): bool => $item !== '');

Handles array_any(), array_all(), array_find(), array_find_key(). Only acts on a ?type param, and skips when the item type is itself nullable.

The two rules are complementary and non-overlapping: one fills a missing type, the other tightens an existing nullable one.

@TomasVotruba TomasVotruba changed the title [type-declaration] Add AddArrayAnyAllClosureParamTypeFromDocblockRector and NarrowArrayAnyAllClosureParamTypeRector [php 8.4] [type-declaration] Add AddArrayAnyAllClosureParamTypeFromDocblockRector and NarrowArrayAnyAllClosureParamTypeRector Jun 19, 2026
@TomasVotruba TomasVotruba changed the title [php 8.4] [type-declaration] Add AddArrayAnyAllClosureParamTypeFromDocblockRector and NarrowArrayAnyAllClosureParamTypeRector [php 8.4] [type-declaration] Add AddArrayAnyAllClosureParamTypeFromDocblockRector and NarrowArrayAnyAllNullableParamTypeRector Jun 19, 2026
…or and NarrowArrayAnyAllClosureParamTypeRector
@TomasVotruba TomasVotruba force-pushed the tv-array-any-all-closure-rule branch from 48387a4 to 42eb26e Compare June 19, 2026 11:47
@TomasVotruba TomasVotruba changed the title [php 8.4] [type-declaration] Add AddArrayAnyAllClosureParamTypeFromDocblockRector and NarrowArrayAnyAllNullableParamTypeRector [php 8.4] [type-declaration] Add AddArrayAnyAllClosureParamTypeRector and NarrowArrayAnyAllNullableParamTypeRector Jun 19, 2026
@TomasVotruba TomasVotruba merged commit f159245 into main Jun 19, 2026
65 checks passed
@TomasVotruba TomasVotruba deleted the tv-array-any-all-closure-rule branch June 19, 2026 11:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant