symplify icon indicating copy to clipboard operation
symplify copied to clipboard

[ECS] ECS fails when working with OperatorLinebreakFixer on PHP < 8.0

Open zingimmick opened this issue 1 year ago • 3 comments

After symplify/easy-coding-standard is upgraded to 11.1.6, vendor/bin/ecs check throws an error on PHP 7.4, but works fine on PHP 8.0.

Reproducible Github repository: https://github.com/zingimmick/ecs-sample

Fatal error: Uncaught TypeError: Argument 1 passed to PhpCsFixer\Fixer\Operator\OperatorLinebreakFixer::PhpCsFixer\Fixer\Operator\{closure}() must be of the type int, string given in /home/runner/work/zingimmick/package/vendor/symplify/easy-coding-standard/vendor/friendsofphp/php-cs-fixer/src/Fixer/Operator/OperatorLinebreakFixer.php:245
Stack trace:
#0 [internal function]: PhpCsFixer\Fixer\Operator\OperatorLinebreakFixer::PhpCsFixer\Fixer\Operator\{closure}('PHPCS_T_NULLSAF...')
#1 /home/runner/work/zingimmick/package/vendor/symplify/easy-coding-standard/vendor/friendsofphp/php-cs-fixer/src/Fixer/Operator/OperatorLinebreakFixer.php(247): array_map(Object(Closure), Array)
#2 /home/runner/work/zingimmick/package/vendor/symplify/easy-coding-standard/vendor/friendsofphp/php-cs-fixer/src/Fixer/Operator/OperatorLinebreakFixer.php(71): PhpCsFixer\Fixer\Operator\OperatorLinebreakFixer::getNonBooleanOperators()
#3 /home/runner/work/zingimmick/package/vend in /home/runner/work/zingimmick/package/vendor/symplify/easy-coding-standard/vendor/friendsofphp/php-cs-fixer/src/Fixer/Operator/OperatorLinebreakFixer.php on line 245

zingimmick avatar Sep 20 '22 14:09 zingimmick

Thanks for reporting.

What exact code in OperatorLinebreakFixer is breaking there?

TomasVotruba avatar Sep 20 '22 14:09 TomasVotruba

The reason is that the squizlabs/php_codesniffer replicated PHP 8.0 tokens for lower versions with string, but the friendsofphp/php-cs-fixer limits the type to int. The token may be of type string: https://github.com/symplify/easy-coding-standard/blob/62d54b722a58430db14e1f4ce1e02636b26950ef/vendor/squizlabs/php_codesniffer/src/Util/Tokens.php#L122-L125

https://github.com/symplify/easy-coding-standard/blob/62d54b722a58430db14e1f4ce1e02636b26950ef/vendor/friendsofphp/php-cs-fixer/src/Fixer/Operator/OperatorLinebreakFixer.php#L243-L248

zingimmick avatar Sep 20 '22 14:09 zingimmick

This is one of the limits of PHP. Constant once defined, cannot be overriden. AFAIK this is not possible to fix, unless both tools use at least same type.

TomasVotruba avatar Sep 20 '22 15:09 TomasVotruba

This is one of the limits of PHP. Constant once defined, cannot be overriden. AFAIK this is not possible to fix, unless both tools use at least same type.

I see. Thank you for your answer.

zingimmick avatar Sep 26 '22 12:09 zingimmick