Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NarrowPublicClassMethodParamTypeRule: wrong error when method is called recusively #36

Open
scollovati opened this issue Jul 9, 2024 · 3 comments

Comments

@scollovati
Copy link

scollovati commented Jul 9, 2024

Example

public function myMethod(string $Id, int $recursive_round = 1): ?array
{
    [...]

    return self::myMethod($Id, 2);
}

Error wrongly reported

Parameters should have "string" types as the only types passed to this method

The parameter should not be removed from the method signature.

@TheoD02
Copy link

TheoD02 commented Jul 10, 2024

Hi,

I'm encountering a similar issue, but in a different context. Here's the situation 😄

Method Definition

public function authenticate(string|false $code = false): ?string

Reported Error

Parameters should have "string|false" types as the only types passed to this method

In my project, I have only two calls to this method:

$accessToken = $this->service->oauth()->authenticate($code);
// and
$accessToken = $this->service->oauth()->authenticate();

Expected Behavior

I expect no error because false is the default value.

Temporary Solution

To resolve this issue for now, I am explicitly setting the default value to false:

$accessToken = $this->deezerClient->oauth()->authenticate(false);

@TomasVotruba
Copy link
Member

Thanks for reporting 👍

Could you add a minimal test fixture test case into the tests? Similar to:
https://github.com/rectorphp/type-perfect/pull/54/files#diff-d59e8ba733575aff2100d3664c8b4cece68c519555707db21d2a43340bb11495

It will be easier and faster for me to fix it then 🤗 Thank you

@scollovati
Copy link
Author

scollovati commented Jan 10, 2025

Thanks for reporting 👍

Could you add a minimal test fixture test case into the tests? Similar to: https://github.com/rectorphp/type-perfect/pull/54/files#diff-d59e8ba733575aff2100d3664c8b4cece68c519555707db21d2a43340bb11495

It will be easier and faster for me to fix it then 🤗 Thank you

I tried to create it here. Hope that it is what you expect: #57

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

No branches or pull requests

3 participants