symplify
symplify copied to clipboard
[ECS] ECS fails when working with OperatorLinebreakFixer on PHP < 8.0
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
Thanks for reporting.
What exact code in OperatorLinebreakFixer
is breaking there?
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
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.
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.