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

Crash on throw expression #6648

Closed
Nek- opened this issue Oct 3, 2022 · 2 comments
Closed

Crash on throw expression #6648

Nek- opened this issue Oct 3, 2022 · 2 comments
Labels

Comments

@Nek-
Copy link

Nek- commented Oct 3, 2022

Hello, first, thank you so much for php-cs-fixer and the work on it.

Now I'm sorry, but I'm going to describe an issue: PHP 8+ allows to use of exception in expression, and sometimes php-cs-fixer acts bad about it...

Bug report

PHP CS Version:

PHP CS Fixer 3.9.5 Grand Awaiting by Fabien Potencier and Dariusz Ruminski.
PHP runtime: 8.1.8

Stack trace

        [InvalidArgumentException]                               
        Invalid param $startIndex - not a proper block "start".  
                                                                 

      PhpCsFixer\Tokenizer\Tokens->findOppositeBlockEdge()
        in /api/tools/php-cs-fixer/vendor/friendsofphp/php-cs-fixer/src/Tokenizer/Tokens.php at line 424
      PhpCsFixer\Tokenizer\Tokens->findBlockEnd()
        in /api/tools/php-cs-fixer/vendor/friendsofphp/php-cs-fixer/src/Fixer/FunctionNotation/SingleLineThrowFixer.php at line 85
      PhpCsFixer\Fixer\FunctionNotation\SingleLineThrowFixer->applyFix()
        in /api/tools/php-cs-fixer/vendor/friendsofphp/php-cs-fixer/src/AbstractFixer.php at line 75
      PhpCsFixer\AbstractFixer->fix()
        in /api/tools/php-cs-fixer/vendor/friendsofphp/php-cs-fixer/src/Runner/Runner.php at line 173
      PhpCsFixer\Runner\Runner->fixFile()
        in /api/tools/php-cs-fixer/vendor/friendsofphp/php-cs-fixer/src/Runner/Runner.php at line 114
      PhpCsFixer\Runner\Runner->fix()
        in /api/tools/php-cs-fixer/vendor/friendsofphp/php-cs-fixer/src/Console/Command/FixCommand.php at line 307
      PhpCsFixer\Console\Command\FixCommand->execute()
        in /api/tools/php-cs-fixer/vendor/symfony/console/Command/Command.php at line 291
      [ ... ]

Code snippet that reproduces the problem

<?php
$var = [
    $something['foo'] ?? throw new Exception('yo')
];

Fix if you have the issue

<?php
$var = [
    $something['foo'] ?? throw new Exception('yo'),
];
@SpacePossum
Copy link
Contributor

Hi and thanks for reporting!

Suggested fix is here #6649

@keradus
Copy link
Member

keradus commented Oct 26, 2022

closed by #6653

@keradus keradus closed this as completed Oct 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants