Skip to content

[deprecation] Deprecate AddParamArrayDocblockBasedOnArrayMapRector - #8340

Merged
TomasVotruba merged 1 commit into
mainfrom
deprecate-param-array-docblock-array-map
Aug 10, 2026
Merged

[deprecation] Deprecate AddParamArrayDocblockBasedOnArrayMapRector#8340
TomasVotruba merged 1 commit into
mainfrom
deprecate-param-array-docblock-array-map

Conversation

@TomasVotruba

Copy link
Copy Markdown
Member

The rule looks for one array_map() call inside a method body, reads the param type of its closure, and writes that as a @param docblock for the whole parameter.

One call site is not evidence about the parameter. The closure only tells us what that single array_map() reads; callers may pass anything else the native array type allows.

 final class SomeClass
 {
+    /**
+     * @param string[] $names
+     */
     public function run(array $names): void
     {
         $names = array_map(fn(string $name) => trim($name), $names);
     }
 }

If any caller passes Name[], or the closure param type is itself just a guess, the docblock is wrong - and PHPStan trusts it over the native array.

Add the docblock manually, or write a custom rule that knows the project's call sites.

Changes:

  • rule implements DeprecatedInterface and throws on refactor()
  • removed from the TypeDeclarationDocblocksLevel set
  • test case + fixtures removed
  • ArrayMapClosureExprFinder removed, it had no other user

@TomasVotruba
TomasVotruba force-pushed the deprecate-param-array-docblock-array-map branch from c42ed46 to a29bd5e Compare August 10, 2026 19:21
@TomasVotruba
TomasVotruba enabled auto-merge (squash) August 10, 2026 19:22
…s a single array_map() call is a vague type source

The rule reads the closure param type of one array_map() call inside the body
and turns it into a @PARAM docblock for the whole parameter. One call site
does not prove what every caller passes, so the added type is often too
narrow. Add the docblock manually instead.
@TomasVotruba
TomasVotruba force-pushed the deprecate-param-array-docblock-array-map branch from a29bd5e to 12eb975 Compare August 10, 2026 19:24
@TomasVotruba
TomasVotruba merged commit cd0b665 into main Aug 10, 2026
54 checks passed
@TomasVotruba
TomasVotruba deleted the deprecate-param-array-docblock-array-map branch August 10, 2026 19:26
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