Skip to content

Conversation

@jrfnl
Copy link
Contributor

@jrfnl jrfnl commented Oct 30, 2021

For use within the loop in the checkAlignment() method, closures are explicitly removed for the $scopeOpeners array as they can be (and often are) assigned to a variable.

However, a closure which contained a parameter with a default value would take the equal sign for the default value as the start of a new block.

The process() method already contained a safeguard against this, but it's the checkAlignment() method which is being called recursively, so this check was not executed for those recursive calls.

Calling the process() method recursively would be troublesome as the returned stackPtr is incremented by one in the process() method, so moving the initial check from the process() method to the checkAlignment() method seemed a reasonable solution.

There will probably be other ways in which this could be solved and I'm not 100% sure this is the best solution, but it is a solution which works without breaking any of the existing unit tests.

Includes a few additional unit tests to further safeguard against this issue and make sure nothing new is broken.

Fixes #3460

…efaults

For use within the loop in the `checkAlignment()` method, closures are explicitly removed for the `$scopeOpeners` array as they can be (and often are) assigned to a variable.

However, a closure which contained a parameter with a default value would take the equal sign for the default value as the start of a new block.

The `process()` method already contained a safeguard against this, but it's the `checkAlignment()` method which is being called recursively, so this check was not executed for those recursive calls.

Calling the `process()` method recursively would be troublesome as the returned stackPtr is incremented by one in the `process()` method, so moving the initial check from the `process()` method to the `checkAlignment()` method seemed a reasonable solution.

There will probably be other ways in which this could be solved and I'm not 100% sure this is the best solution, but it is a solution which works without breaking any of the existing unit tests.

Includes a few additional unit tests to further safeguard against this issue and make sure nothing new is broken.
@jrfnl jrfnl force-pushed the feature/3460-generic-multiplestatement-closure-param-bug branch from 5616d5a to 1f39246 Compare October 30, 2021 13:50
@gsherwood gsherwood added this to the 3.6.2 milestone Dec 3, 2021
gsherwood added a commit that referenced this pull request Dec 6, 2021
@gsherwood gsherwood merged commit 2bea753 into squizlabs:master Dec 6, 2021
@gsherwood
Copy link
Member

Thanks for fixing this. Very happy to accept a straightforward fix that doesn't break anything :)

@jrfnl jrfnl deleted the feature/3460-generic-multiplestatement-closure-param-bug branch December 6, 2021 21:50
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.

Generic.Formatting.MultipleStatementAlignment false positive on closure with parameters

2 participants