Restore declare_strict_types enforcement (STF-223)#239
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces strict type declarations to the project by updating the PHP-CS-Fixer configuration and adding the declaration to the benchmark example. A review comment suggests using a boolean value for the 'declare_strict_types' rule instead of an array to maintain backward compatibility with older versions of the fixer and ensure consistency with other rules in the configuration file.
| 'array_syntax' => ['syntax' => 'short'], | ||
| 'combine_consecutive_unsets' => true, | ||
| 'concat_space' => [ 'spacing' => 'one'], | ||
| 'declare_strict_types' => ['strategy' => 'enforce'], |
There was a problem hiding this comment.
Using true instead of an explicit array for this rule is preferred here. The strategy option was introduced in php-cs-fixer v3.95.0; using it will cause older versions of the fixer to fail with an 'unknown option' error. Since the default strategy for this rule is enforce, using true achieves the same result while maintaining backward compatibility for contributors using older versions of the tool and staying consistent with other boolean rules in this file.
'declare_strict_types' => true,php-cs-fixer v3.95.0 added a `strategy` option to `declare_strict_types` and set `@Symfony:risky` to `'strategy' => 'remove'` (see PHP-CS-Fixer/PHP-CS-Fixer#9384), which causes the preset we inherit to strip `declare(strict_types=1);` from every file on the next CI run. Override with `'strategy' => 'enforce'` to keep the pre-v3.95 behavior — strict types stay declared. The one example file that didn't already have the declaration had it added by the fixer; it is not part of the library's public API. Closes STF-223.
Summary
@Symfony:riskypreset to applydeclare_strict_typeswith'strategy' => 'remove', which stripsdeclare(strict_types=1);from every file on the next CI run.'strategy' => 'enforce'so the pre-v3.95 behavior is preserved and strict types stay declared.declare(strict_types=1);toexamples/benchmark.php— not public API, so this is not user-visible.Closes STF-223.
Test plan
vendor/bin/php-cs-fixer fix --dry-run --diffclean locallyvendor/bin/phpcs --standard=PSR2 src/clean locallyvendor/bin/phpstan analyzeclean locallyPHP LintsCI job green on this PR