Skip to content

Conversation

@TomasVotruba
Copy link
Member

@TomasVotruba TomasVotruba commented Sep 12, 2025

This rules adds known @param docblock for keys used in method body 👍

 final class ParamArray
 { 
+    /**
+     * @param array<string, mixed> $data
+     */
     public function process(array $data): void
     {
         $item = $data['key'];

         $anotherItem = $data['another_key'];
     }
 }

@TomasVotruba TomasVotruba force-pushed the tv-add-param-based-on-array-dim-fetch-access branch from e8f7f30 to 2a1295a Compare September 12, 2025 12:00
@TomasVotruba TomasVotruba enabled auto-merge (squash) September 12, 2025 12:00
@TomasVotruba TomasVotruba merged commit 01a21ae into main Sep 12, 2025
49 checks passed
@TomasVotruba TomasVotruba deleted the tv-add-param-based-on-array-dim-fetch-access branch September 12, 2025 12:01
@samsonasik
Copy link
Member

samsonasik commented Sep 12, 2025

It seems mostly got mixed value, which may be int or string, eg:

function foo(array $params, int $page, int $limit)
{
   $params['page'] = $page;
   $params['limit'] = $limit;
}

got:

+/**
+ * @param array<string, mixed> $params
+ */

which I think should possibly:

+/**
+ * @param array<string, int> $params
+ */

@TomasVotruba
Copy link
Member Author

TomasVotruba commented Sep 12, 2025

That doesn't have to be true, as $params can contains even string and other values.

@TomasVotruba
Copy link
Member Author

Do you have some real-world file where this rule should be improved? More context would help

@samsonasik
Copy link
Member

Yes, on our project 👍 , using blindly set to mixed will cause everything like mixed, while it on use is not.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants