Skip to content

Restore declare_strict_types enforcement (STF-223)#239

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

Restore declare_strict_types enforcement (STF-223)#239
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.
  • The fixer added declare(strict_types=1); to examples/benchmark.php — not public API, so this is not user-visible.

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 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.

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 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.
@horgh horgh merged commit 6a1e42c into main Apr 21, 2026
83 checks passed
@horgh horgh deleted the greg/stf-223 branch April 21, 2026 19:39
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