Php-cs-fixer: Multi lines symfony expression removed from annotations since 2.15.4

Created on 17 Mar 2020  Â·  3Comments  Â·  Source: FriendsOfPHP/PHP-CS-Fixer

Description:

Since I've updated PHP-CS-Fixer from 2.15.1 to 2.16.1, I have my symfony expression under my access_controls annotations of ApiPlatform getting deleted as if it's an invalid code and without any configuration change.

This was working well on 2.15.1. I made the test on several versions and I found that :
It it bugged on 2.15.4 and 2.15.5 but worked on 2.15.2, 2.15.3.

Seems related to #1794, but disabling phpdoc_trim does not works.

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

=> PHP 7.3.14 (cli) (built: Jan 24 2020 08:45:02) ( NTS )

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

The command you use to run PHP CS Fixer:

=> vendor/bin/php-cs-fixer fix

The configuration file you are using, if any:

<?php

$finder = PhpCsFixer\Finder::create()
    ->in(__DIR__.'/src')
    ->in(__DIR__.'/tests')
    ->in(__DIR__.'/features/bootstrap')
;

return PhpCsFixer\Config::create()
    ->setRules([
        '@Symfony' => true,
        '@DoctrineAnnotation' => true,
        'array_syntax' => ['syntax' => 'short'],
        'concat_space' => ['spacing' => 'none'],
        'multiline_whitespace_before_semicolons' => ['strategy' => 'new_line_for_chained_calls'],
        'native_constant_invocation' => true,
        'native_function_invocation' => ['include' => ['@compiler_optimized']],
        'no_superfluous_phpdoc_tags' => true,
        'no_unneeded_final_method' => false,
        'ordered_imports' => ['sort_algorithm' => 'alpha'],
        'phpdoc_summary' => false,
        'phpdoc_to_comment' => false,
        'strict_param' => true,
        'cast_spaces' => ['space' => 'single'],
        'phpdoc_separation' => [],
    ])
    ->setRiskyAllowed(true)
    ->setUsingCache(true)
    ->setFinder($finder)
;

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

  • before running PHP CS Fixer (no changes):
/**
 * @ApiResource(
 *     itemOperations={
 *         "get": {"access_control": "
                (
                    is_granted('PERM1') && (is_granted('IS_AUTHOR', object.getAuthor()) ||
                    is_granted('BELONG_TO_GROUP', object.getContributionGroup()))
                )
                && is_granted('PERM2', object)
           "}
 * )
 */
  • with unexpected changes applied when running PHP CS Fixer:
/**
 * @ApiResource(
 *     itemOperations={
 *         "get": {"access_control": "
           "}
 * )
 */
  • with the changes you expected instead:
/**
 * @ApiResource(
 *     itemOperations={
 *         "get": {"access_control": "
                (
                    is_granted('PERM1') && (is_granted('IS_AUTHOR', object.getAuthor()) ||
                    is_granted('BELONG_TO_GROUP', object.getContributionGroup()))
                )
                && is_granted('PERM2', object)
           "}
 * )
 */
kinbug statuto verify

All 3 comments

Thanks for reporting! This looks like a bug, can you maybe check if it is the same bug as https://github.com/FriendsOfPHP/PHP-CS-Fixer/issues/4681 ?

@SpacePossum Sorry, I ain't noticed you answer. It seems to be the exact same case but on an other usage of multilined Symfony Expression Language Component.

thanks for checking,
I'm going to close this report as valid yet a duplicate, if we find it there is another cause of the issue here than I'm happy to reopen of course

Was this page helpful?
0 / 5 - 0 ratings