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.
$ php -v):=> PHP 7.3.14 (cli) (built: Jan 24 2020 08:45:02) ( NTS )
$ php-cs-fixer -V):=> PHP CS Fixer 2.16.1 Yellow Bird by Fabien Potencier and Dariusz Ruminski
=> vendor/bin/php-cs-fixer fix
<?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)
;
/**
* @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)
"}
* )
*/
/**
* @ApiResource(
* itemOperations={
* "get": {"access_control": "
"}
* )
*/
/**
* @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)
"}
* )
*/
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