Skip to content

Restore declare_strict_types enforcement (STF-223)#255

Merged
horgh merged 1 commit into
mainfrom
greg/stf-223
Apr 21, 2026
Merged

Restore declare_strict_types enforcement (STF-223)#255
horgh merged 1 commit into
mainfrom
greg/stf-223

Conversation

@oschwald
Copy link
Copy Markdown
Member

Summary

  • php-cs-fixer v3.95.0 changed the @Symfony:risky preset to apply declare_strict_types with 'strategy' => 'remove', which strips declare(strict_types=1); from every file on the next CI run.
  • Override the rule with '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 --diff clean locally
  • vendor/bin/phpcs --standard=PSR2 src/ clean locally
  • vendor/bin/phpstan analyze clean locally
  • PHP Lints CI job green on this PR

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread .php-cs-fixer.php Outdated
'array_syntax' => ['syntax' => 'short'],
'combine_consecutive_unsets' => true,
'concat_space' => [ 'spacing' => 'one'],
'declare_strict_types' => ['strategy' => 'enforce'],
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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.
@horgh horgh merged commit 42d0917 into main Apr 21, 2026
48 of 51 checks passed
@horgh horgh deleted the greg/stf-223 branch April 21, 2026 19:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants