Restore declare_strict_types enforcement (STF-223)#255
Conversation
There was a problem hiding this comment.
Code Review
This pull request updates the .php-cs-fixer.php configuration to include the declare_strict_types rule. The reviewer suggested using the boolean true for this rule instead of the array syntax to maintain backward compatibility with older versions of PHP-CS-Fixer v3.
| '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 'declare_strict_types' => true is more concise and provides better backward compatibility. The strategy option was introduced in PHP-CS-Fixer v3.65.0. Since the composer.json file allows any version of 3.*, using the boolean true ensures the rule is enabled with its default configuration (which is ['strategy' => 'enforce']) across all versions of PHP-CS-Fixer v3. This avoids potential configuration errors in environments where the tool hasn't been updated to v3.65+ yet, while still correctly overriding the @Symfony:risky preset's new behavior.
'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. 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.Every PHP file already had
declare(strict_types=1);, so nothing else changed in this repo.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