Php-cs-fixer: PHP Parse error: syntax error, unexpected ':' Nested if with mixed braces and endif

Created on 21 Jan 2020  路  2Comments  路  Source: FriendsOfPHP/PHP-CS-Fixer

Files that were not fixed due to errors reported during linting before fixing:

[PhpCsFixer\Linter\LintingException]
PHP Parse error: syntax error, unexpected ':' on line 10.

The PHP version you are using ($ php -v):

PHP 7.3.9 (cli) (built: Nov  9 2019 08:08:13) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.3.9, Copyright (c) 1998-2018 Zend Technologies

PHP CS Fixer version you are using ($ php-cs-fixer -V):

PHP CS Fixer 2.16.1 Yellow Bird by Fabien Potencier and Dariusz Ruminski (c8afb59)

The command you use to run PHP CS Fixer:

php-cs-fixer fix -vvv --rules=indentation_type test-nested-if-endif.php

If applicable, please provide minimum samples of PHP code (as plain text, not screenshots):

  • before running PHP CS Fixer (no changes):
<?php

$test = true;
$another = false;

if ($test):
    if ($another) {
    echo 'test another';
    }
else:
    if ($another) {
    echo 'another';
    }
endif;
  • with unexpected changes applied when running PHP CS Fixer:
[PhpCsFixer\Linter\LintingException]
PHP Parse error: syntax error, unexpected ':' on line 10.
  • with the changes you expected instead:
<?php

$test = true;
$another = false;

if ($test):
    if ($another) {
        echo 'test another';
    }
else:
    if ($another) {
        echo 'another';
    }
endif;
kinquestion

All 2 comments

Hi and thanks for your report,

Both the before code and expected code is not valid PHP, that is why it cannot be fixed by the tool. This is a limitation by design,

@SpacePossum thank you for spotting that

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Bilge picture Bilge  路  3Comments

EvgenyOrekhov picture EvgenyOrekhov  路  3Comments

Bilge picture Bilge  路  3Comments

aidantwoods picture aidantwoods  路  3Comments

BackEndTea picture BackEndTea  路  3Comments