Skip to content

feat: support keeping strict_types=0 in DeclareStrictTypesFixer#9121

Merged
keradus merged 4 commits intoPHP-CS-Fixer:masterfrom
mlocati-forks:feat-declare-keep-non-strict
Oct 3, 2025
Merged

feat: support keeping strict_types=0 in DeclareStrictTypesFixer#9121
keradus merged 4 commits intoPHP-CS-Fixer:masterfrom
mlocati-forks:feat-declare-keep-non-strict

Conversation

@mlocati
Copy link
Copy Markdown
Contributor

@mlocati mlocati commented Oct 2, 2025

I have a couple of cases where I have to keep declare(strict_types=0).

What about improving the declare_strict_types fixer so that it can keep existing declare(strict_types=0), but still add declare(strict_types=1) if strict_types is not declared?

@coveralls
Copy link
Copy Markdown

coveralls commented Oct 2, 2025

Coverage Status

coverage: 94.148% (-0.001%) from 94.149%
when pulling f0bfa8c on mlocati-forks:feat-declare-keep-non-strict
into e0516ca on PHP-CS-Fixer:master.

@kubawerlos kubawerlos requested a review from keradus October 2, 2025 18:56
@kubawerlos
Copy link
Copy Markdown
Member

@kubawerlos kubawerlos requested a review from keradus

Since this is related to #8877, I am not sure what the conclusion is. Otherwise, the PR looks good.

@mlocati
Copy link
Copy Markdown
Contributor Author

mlocati commented Oct 2, 2025

Of course this fixer can be improved to cover any user necessity...

What about these configuration options:

  • presence bool|null (true: always there, false: never there, null: don't add/remove, just work on existing, if any)
  • update bool (false: don't update the value if there, true: otherwise)
  • value 0|1 (the value to be set/updated)

The current behavior (so, default values) would be:

  • presence: true
  • update: true
  • value: 1

@mlocati
Copy link
Copy Markdown
Contributor Author

mlocati commented Oct 2, 2025

... and with #9107 it will be possible to use a specific configuration for specific files

Comment thread src/Fixer/Strict/DeclareStrictTypesFixer.php
Comment thread src/Fixer/Strict/DeclareStrictTypesFixer.php Outdated
Copy link
Copy Markdown
Member

@keradus keradus left a comment

Choose a reason for hiding this comment

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

thank you, nice one

@keradus keradus merged commit e3f09a0 into PHP-CS-Fixer:master Oct 3, 2025
32 of 33 checks passed
@mlocati mlocati deleted the feat-declare-keep-non-strict branch October 3, 2025 14:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants