-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Rule declare_strict_types
does not work on files that start with a "hashbang" line
#7634
Comments
potential testcase: diff --git a/tests/Fixer/Strict/DeclareStrictTypesFixerTest.php b/tests/Fixer/Strict/DeclareStrictTypesFixerTest.php
index 709d50456..f42e138a6 100644
--- a/tests/Fixer/Strict/DeclareStrictTypesFixerTest.php
+++ b/tests/Fixer/Strict/DeclareStrictTypesFixerTest.php
@@ -130,6 +130,15 @@ class A {
'<?php declare(strict_types=0);',
];
+ yield [
+ "#!/usr/bin/env php
+<?php declare(strict_types=1);
+echo 'foo';",
+ "#!/usr/bin/env php
+<?php
+echo 'foo';",
+ ];
@krzysztof-sikorski , would you like to give it a try? |
promoting to feature due to https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/blob/master/feature-or-bug.rst |
@keradus I'm not sure if I fully understand the project's architecture but yes, I am willing to try. Because this issue got classified as a feature instead of bug, then maybe the new behaviour should be configurable and disabled by default, to keep backward compatibility? |
Thanks! I'm open to have it behind config |
Bug report
Description
The rule
declare_strict_types
does not work on files that start with a "hashbang" line:I discovered the bug when I tried to reformat a
bin/console
file generated by Symfony CLI,but further testing soon revealed that the rule simply ignores "mixed content" files
that contain any non-PHP lines before the
<php
opening tag.While I understand that the behaviour might be intentional (to avoid corrupting files
where the
declare
statement would have no effect or wrong effect), I also think thatthe hashbang line should be an exception and files that start with it but contain no other
non-PHP content should be treated as "pure PHP" files and modified by the rule.
Runtime version
Used command
vendor/bin/php-cs-fixer -vvv fix
Configuration file
Code snippet that reproduces the problem
Expected result:
Actual result: file is not changed at all.
Here is a simple repository that demonstrates the bug:
https://github.com/krzysztof-sikorski/php-cs-fixer-declare-strict-types-bug
Just pull the code, execute
composer install
, and thenvendor/bin/php-cs-fixer -vvv fix
.The text was updated successfully, but these errors were encountered: