Skip to content

phpcbf on if/else with trailing comment generates erroneous code #1190

@shadiakiki1986

Description

@shadiakiki1986

I have a file test.php with the following content

<?php $out=array_map(function($test) { if($test) return 1; else return 2; }, $input); $out=array_map(function($test) { if($test) return 1; else return 2; }, $input); // this line is as the above but with a trailing comment 

when I run vendor/bin/phpcbf test.php, I get the following fixed file

<?php $out=array_map( function ($test) { if($test) { return 1; } else { return 2; } }, $input ); $out=array_map( function ($test) { if($test) { return 1; else { return 2; } }, $input ); // this line is as the above but with a trailing comment } 

Notice the if brace did not close before the else, and that the array_map parentheses close too early.
I'm using "squizlabs/php_codesniffer": "^2.7" in my composer.json file

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions