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

Suggestion: make isset, unset and empty parenthesis owners #3118

Closed
jrfnl opened this issue Sep 19, 2020 · 3 comments
Closed

Suggestion: make isset, unset and empty parenthesis owners #3118

jrfnl opened this issue Sep 19, 2020 · 3 comments

Comments

@jrfnl
Copy link
Contributor

jrfnl commented Sep 19, 2020

I was just wondering why isset(), unset() and empty() - all language constructs which require parentheses - are not considered parentheses owners.

Would it make sense to change that ? Should be a relatively easy change to make as far as I can see.

Happy to make the changes if there is interest.


[Edit]: Might be useful to include exit(), die() and eval() as well, though these three don't require parentheses, but are "owners" when the parentheses are present.

jrfnl added a commit to PHPCSStandards/PHPCSUtils that referenced this issue Sep 20, 2020
PHPCS natively does not consider `isset()`, `unset()`, `empty()`, `exit()`, `die()` and `eval()` as parentheses owners.

As of now, the methods in the PHPCSUtils `Parentheses` class will.

If effect, this means you can now check whether an arbitrary token is within an `isset()`, `unset()` or `empty()` call by calling:
```php
if (Parentheses::hasOwner($phpcsFile, $stackPtr, [\T_ISSET, \T_UNSET, \T_EMPTY]) !== false) {
    // Do something.
}
```

Related issue upstream: squizlabs/PHP_CodeSniffer#3118
@gsherwood
Copy link
Member

Makes sense to me. For the constructs that don't require parenthesis, just need to make sure they don't go hunting for unowned ones and claiming them, although this may already be protected against.

@jrfnl
Copy link
Contributor Author

jrfnl commented Sep 22, 2020

For the constructs that don't require parenthesis, just need to make sure they don't go hunting for unowned ones and claiming them, although this may already be protected against.

Eh.. not really... that's part of the problem with closure T_USE as parenthesis owner for which PR #3104 is open.....

With that in mind, should this be addressed in PHPCS 3.x or 4.x ? (PR #3104 is for 4.x and includes part of the protection which would need to be added for the above as well.)

@jrfnl
Copy link
Contributor Author

jrfnl commented Dec 2, 2023

Closing as replaced by PHPCSStandards/PHP_CodeSniffer#23

@jrfnl jrfnl closed this as not planned Won't fix, can't repro, duplicate, stale Dec 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Ready for Release
Development

No branches or pull requests

2 participants