rectorphp / type-perfect

Next level type declaration check PHPStan rules
https://getrector.com/blog/introducing-type-perfect-for-extra-safety
MIT License
74 stars 4 forks source link

NarrowPublicClassMethodParamTypeRule: Don't suggest array types #34

Closed staabm closed 1 month ago

staabm commented 3 months ago

I think the rule is going too far, when suggesting phpdoc-array types for a method which is already typed as a native array type

we get errors like

 ------ --------------------------------------------------------------------------------------------------------------------
  Line   kunzmann\app\shared\models\Land.php
 ------ --------------------------------------------------------------------------------------------------------------------
  106    Land->getListArray: Parameters should have "array<string, int>" types as the only types passed to this method
  118    Land->getListArrayNames: Parameters should have "array<string, int>" types as the only types passed to this method
 ------ --------------------------------------------------------------------------------------------------------------------

for our methods

class Land
{
    public function getListArray(array $con = []): array
    {
    }

    public function getListArrayNames(array $con = []): array
    {
    }
}

and because arrays are used a lot in php projects, these errors flood the phpstan reporting, so way more interessting errors can easily be overlooked.

wdyt about making the rule happy, when a parameter is already natively array-typed?

staabm commented 3 months ago

I also had a case where the rule error was

Parameters should have \"array\|array\" types as the only types passed to this method

and I don't understand what the error is trying to tell me. maybe there is some kind of overlap with https://github.com/rectorphp/type-perfect/issues/35

TomasVotruba commented 3 months ago

Failing test fixture PR is needed 👍

staabm commented 3 months ago

test-case in https://github.com/rectorphp/type-perfect/pull/38

TomasVotruba commented 1 month ago

Going through stale issues and closing "the ideas" one to keep focus on PRs and change. Feel free to propose a PR with a fix/feature :+1:

Thanks for understanding