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

File::getMethodParameters() setting typeHintEndToken for vars with no type hint #2685

Merged

Conversation

jrfnl
Copy link
Contributor

@jrfnl jrfnl commented Nov 10, 2019

Given the following code sample:

function foo( ?bool $a, $b ) {}

In the resulting array, the second parameter $b will have the 'type_hint_end_token' index set to the stack pointer for the end of the type declaration for $a, instead of it being the expected false.

Caused by the $typeHintEndToken not being reset for the next parameter.

I've re-ordered the variable reset now to be the same as the order used for the initial variable declarations before the loop to make it more obvious.

While not necessarily a bug, the $currVar variable was also not being reset. That's also been fixed now.

I've not added a unit test as the existing tests do not check the token positions in the array.

Given the following code sample:
```php
function foo( ?bool $a, $b ) {}
```

In the resulting array, the second parameter `$b` will have the 'type_hint_end_token' set to the stack pointer for the end of the type declaration for `$a`.

Caused by the `$typeHintEndToken` not being reset for the next parameter.

I've re-ordered the variable reset now to be the same as the order used for the initial variable declarations before the loop to make it more obvious.

While not necessarily a bug, the `$currVar` variable was also not being reset. That's also been fixed now.

I've not added a unit test as the existing tests do not check the token positions in the array.
@gsherwood gsherwood added this to Idea Bank in PHPCS v3 Development via automation Nov 10, 2019
@gsherwood gsherwood added this to the 3.5.3 milestone Nov 10, 2019
@gsherwood gsherwood changed the title File::getMethodParameters(): fix incorrect $typeHintEndToken File::getMethodParameters() setting typeHintEndToken for vars with no type hint Nov 11, 2019
gsherwood added a commit that referenced this pull request Nov 11, 2019
@gsherwood gsherwood merged commit 1b96fdb into squizlabs:master Nov 11, 2019
PHPCS v3 Development automation moved this from Idea Bank to Ready for Release Nov 11, 2019
@gsherwood
Copy link
Member

Thanks for the fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
PHPCS v3 Development
Ready for Release
Development

Successfully merging this pull request may close these issues.

None yet

2 participants