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

SlevomatCodingStandard.PHP.UselessParentheses.UselessParentheses - false positive with modulo operator #1678

Open
rvock opened this issue May 16, 2024 · 1 comment

Comments

@rvock
Copy link

rvock commented May 16, 2024

<?php
declare(strict_types = 1);

var_dump(!(12 % 12));
var_dump(!12 % 12);

Output:

bool(true)
int(0)

Here I get an error, that the first parentheses are useless. But that's not the case, because the output is different, if I remove them.

The ! operator has a higher precedence than the module % operator:
https://www.php.net/manual/en/language.operators.precedence.php

@bkdotcom
Copy link
Contributor

bkdotcom commented May 16, 2024

See also #1674 (bit-shift operator) & #1672 (string concat & ternary operator)

This sniff doesn't seem to take context into account?
3 * (2 + 1) doesn't trigger UselessParentheses though ¯\_(ツ)_/¯

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

2 participants