Skip to content

Restore declare_strict_types enforcement (STF-223)#302

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

Restore declare_strict_types enforcement (STF-223)#302
horgh merged 1 commit intomainfrom
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 and dev-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 --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 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.

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

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.
@horgh horgh merged commit 2f342a7 into main Apr 21, 2026
44 of 51 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