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

Hooks logic fails for short array syntax #358

Closed
1 task done
GaryJones opened this issue Jan 16, 2019 · 5 comments
Closed
1 task done

Hooks logic fails for short array syntax #358

GaryJones opened this issue Jan 16, 2019 · 5 comments
Assignees
Milestone

Comments

@GaryJones
Copy link
Contributor

GaryJones commented Jan 16, 2019

Changing to short array syntax in Tests/Hooks/AlwaysReturnInFilterUnitTests.inc and Tests/Hooks/PreGetPostsUnitTests.inc result in those tests failing.

It suggests that some of the processing logic in each sniff is flawed for short array syntaxes.

Both long and short array syntax should be retained in the unit tests.

Environment

Use php -v and composer show to get versions.

Question Answer
PHP version 7.2.0
PHP_CodeSniffer version 3.4.0
VIPCS version master

Tested Against master branch?

  • I have verified the issue still exists in the master branch of VIPCS.
@GaryJones
Copy link
Contributor Author

The line of logic is:

elseif ( 'T_ARRAY' === $this->_tokens[ $callbackPtr ]['type'] )

which presumably misses checking for an array of the [ ... ] form.

@GaryJones
Copy link
Contributor Author

It's not as simple as adding a check for T_OPEN_SHORT_ARRAY.

Ideally, we want to be able to use this WPCS method to accurately handle this.

See #359 for how this might be possible.

@GaryJones
Copy link
Contributor Author

Now that #377 is merged, we can use the WPCS method to fix/improve our sniff.

@GaryJones GaryJones modified the milestones: 1.0.0, Future Release Mar 7, 2019
@GaryJones GaryJones modified the milestones: Future Release, 2.1 Jul 13, 2019
@GaryJones
Copy link
Contributor Author

WPCS 3.0 will likely that utility method, as it will depend on the utility methods in PHPCSUtils instead.

Good news is, after #474 is done, we can use these PHPCSUtils utility methods ourselves.

jrfnl added a commit that referenced this issue Jul 28, 2020
As VIPCS is currently using WPCS 2.x, we can use the WPCS `Sniff::find_array_open_close()` method to get the opener/closer for an array independently of the type of array (long/short).

Once VIPCS implements PHPCSUtils, this method call should be swopped out for the PHPCSUtils `Arrays::getOpenClose()` method.

Addresses #358 for the `AlwaysReturnInFilter` sniff.

Includes unit tests.
jrfnl added a commit that referenced this issue Jul 28, 2020
As VIPCS is currently using WPCS 2.x, we can use the WPCS `Sniff::find_array_open_close()` method to get the opener/closer for an array independently of the type of array (long/short).

Once VIPCS implements PHPCSUtils, this method call should be swopped out for the PHPCSUtils `Arrays::getOpenClose()` method.

Addresses #358 for the `PreGetPosts` sniff.

Includes unit tests.
jrfnl added a commit that referenced this issue Jul 29, 2020
As VIPCS is currently using WPCS 2.x, we can use the WPCS `Sniff::find_array_open_close()` method to get the opener/closer for an array independently of the type of array (long/short).

Once VIPCS implements PHPCSUtils, this method call should be swopped out for the PHPCSUtils `Arrays::getOpenClose()` method.

Addresses #358 for the `PreGetPosts` sniff.

Includes unit tests.
@jrfnl
Copy link
Collaborator

jrfnl commented Jul 29, 2020

As #563 and #564 are now both merged, I believe this issue is fixed and can be closed.

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

No branches or pull requests

2 participants