Restore declare_strict_types enforcement (STF-223)#302
Conversation
There was a problem hiding this comment.
Code Review
This pull request implements strict typing across the project by adding declare(strict_types=1) to several PHP files and updating the .php-cs-fixer.php configuration. A review comment points out that the new strategy option for the declare_strict_types rule requires php-cs-fixer v3.64.0 or higher, suggesting a necessary update to the composer.json file to prevent potential fatal errors in environments running older versions of the tool.
| 'array_syntax' => ['syntax' => 'short'], | ||
| 'combine_consecutive_unsets' => true, | ||
| 'concat_space' => [ 'spacing' => 'one'], | ||
| 'declare_strict_types' => ['strategy' => 'enforce'], |
There was a problem hiding this comment.
The strategy option for the declare_strict_types rule was introduced in a recent version of php-cs-fixer (v3.64.0). Since the composer.json currently allows any version within the 3.* range, this configuration will cause a fatal error for any developer or CI environment running an older version of the tool (e.g., v3.63.0 or below). It is recommended to update the minimum version of friendsofphp/php-cs-fixer in composer.json to at least ^3.64.0 to ensure the configuration remains valid across all environments.
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 two example/dev-tool files that didn't already have the declaration had it added by the fixer; neither is 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.phpanddev-bin/phar-test.php— neither is 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