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

fully_qualified_strict_types breaks header_comment #7680

Closed
mvorisek opened this issue Jan 5, 2024 · 2 comments · Fixed by #7679
Closed

fully_qualified_strict_types breaks header_comment #7680

mvorisek opened this issue Jan 5, 2024 · 2 comments · Fixed by #7679
Labels

Comments

@mvorisek
Copy link
Contributor

mvorisek commented Jan 5, 2024

Bug report

image

It seems fully_qualified_strict_types adds the uses above declare(strict_types=1) leading to header comment duplication by header_comment.

Maybe only a priority issue as declare_strict_types should asserts the declare(strict_types=1) is always the first statement after <?php.

fully_qualified_strict_types should be however fixed too to add the uses after the strict declare statement.

Quick help welcomed as the last PHP CS Fixer updated started to add a lot of use imports but the duplicated header is never removed by any fixer!

@mvorisek
Copy link
Contributor Author

mvorisek commented Jan 5, 2024

image

Even breaking code when shebang is present!

with such diff/code, MultilineWhitespaceBeforeSemicolonsFixer fixer crashes:

        [RuntimeException]
        Index invalid or out of range


      PhpCsFixer\Fixer\Semicolon\MultilineWhitespaceBeforeSemicolonsFixer->findWhitespaceBeforeFirstCall()
        in ...src\Fixer\Semicolon\MultilineWhitespaceBeforeSemicolonsFixer.php at line 112
      PhpCsFixer\Fixer\Semicolon\MultilineWhitespaceBeforeSemicolonsFixer->applyFix()
        in ...src\AbstractFixer.php at line 75
      PhpCsFixer\AbstractFixer->fix()
        in ...src\Runner\Runner.php at line 173
      PhpCsFixer\Runner\Runner->fixFile()
        in ...src\Runner\Runner.php at line 114
      PhpCsFixer\Runner\Runner->fix()
        in ...src\Console\Command\FixCommand.php at line 303
      PhpCsFixer\Console\Command\FixCommand->execute()
        in ...vendor\symfony\console\Command\Command.php at line 298

@Wirone
Copy link
Member

Wirone commented Jan 5, 2024

This must be improved here, I did not take no-namespace files into consideration 😕. Probably imports should be inserted before the first statement other than declare.

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