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

False positive constant on native_constant_invocation rule #6271

Closed
benjaminmal opened this issue Feb 5, 2022 · 2 comments
Closed

False positive constant on native_constant_invocation rule #6271

benjaminmal opened this issue Feb 5, 2022 · 2 comments
Labels

Comments

@benjaminmal
Copy link

Bug report

Versions

  • PHP-CS-Fixer: from 3.2.0 to 3.5.0
  • PHP runtime : 8.0.9

The native_constant_invocation rules seems to interprete the 2nd object as a constant when it's in a catch statement with another object but without the exception variable (from PHP 8). See:

try {
    // Code
} catch (MyException|\TypeError) {
    // Code
} catch (MyException|\TypeError $e) {
    // Code
} catch (\TypeError|\ErrorException) {
    // Code
} catch (\ErrorException|\TypeError) {
    // Code
} catch (\TypeError) {
    // Code
}

Code snippet that reproduces the problem

php-cs-fixer fix test.php --rules=native_constant_invocation --allow-risky=yes --diff --dry-run -v
PHP CS Fixer 3.5.0 The Creation by Fabien Potencier and Dariusz Ruminski.
PHP runtime: 8.0.9
Loaded config default.
Using cache file ".php-cs-fixer.cache".
F                                                                   1 / 1 (100%)
Legend: ?-unknown, I-invalid file syntax (file ignored), S-skipped (cached or empty file), .-no changes, F-fixed, E-error
   1) test.php (native_constant_invocation)
      ---------- begin diff ----------
--- "test-phpcs/test.php"
+++ "test-phpcs/test.php"
@@ -6,13 +6,13 @@

 try {
     // Code
-} catch (MyException|\TypeError) {
+} catch (MyException|TypeError) {
     // Code
 } catch (MyException|\TypeError $e) {
     // Code
-} catch (\TypeError|\ErrorException) {
+} catch (\TypeError|ErrorException) {
     // Code
-} catch (\ErrorException|\TypeError) {
+} catch (\ErrorException|TypeError) {
     // Code
 } catch (\TypeError) {
     // Code

      ----------- end diff -----------


Checked all files in 0.017 seconds, 12.000 MB memory used
@SpacePossum
Copy link
Contributor

thanks for reporting and all the details provided 👍

I think this is the same as #5684 (comment) so the fix will solve this, let me know if not

@benjaminmal
Copy link
Author

@SpacePossum Sorry, I didn't see it!

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

No branches or pull requests

2 participants