Skip to content

refactor: use the 8.3 features that carry weight - #34

Merged
refsz merged 1 commit into
build/require-php-83from
refactor/php-83-features
Aug 19, 2026
Merged

refactor: use the 8.3 features that carry weight#34
refsz merged 1 commit into
build/require-php-83from
refactor/php-83-features

Conversation

@refsz

@refsz refsz commented Aug 19, 2026

Copy link
Copy Markdown
Owner

Follow-up to #33, kept separate so the version bump stays mechanical. Merge #33 first; GitHub retargets this to main.

Two changes, both with a reason beyond "8.3 allows it":

The typed class constant comes back. private const array DEFAULT_SHELL in EnvironmentDetector had to lose its type under 8.2, with PHPStan naming the reason.

#[Override] on the redacting decorators. This is not decoration. The masking leak found earlier today was exactly a method that no longer matched its parent: ConsoleSectionOutput::overwrite() takes a cursor-rewind path on a decorated terminal that writes via doWrite() directly, bypassing the write() and writeln() overrides — and nothing failed, output just quietly stopped being redacted. I found it by reading Symfony's source, which is not a strategy.

With the attribute, a renamed or resignatured parent method is a fatal error at load time:

PHP Fatal error: Sputnik\Secret\RedactingConsoleSectionOutput::overwriteTypo()
has #[\Override] attribute, but no matching parent method exists

That output is from actually renaming one override and watching the class refuse to load, then reverting. It is the cheapest possible guard on the six methods where a silent mismatch means a secret reaches the terminal.

Deliberately not included

  • Typing every existing constant. PHPStan already infers precise types from literals, so a sweep would change 12 files for style alone.
  • Rewriting withFormatter() as a clone. I claimed in build!: require PHP 8.3 #33 that 8.3 makes this possible and then checked it: readonly properties may be reinitialised only inside __clone(), which cannot receive the new value. Outside it, PHP still throws Cannot modify readonly property. The existing new self(...) is correct and stays.

Verification

vendor/bin/phpunit          742 tests, 1281 assertions, OK
vendor/bin/phpstan analyse  [OK] No errors
vendor/bin/php-cs-fixer     0 of 153 files
vendor/bin/rector --dry-run [OK]

🤖 Generated with Claude Code

https://claude.ai/code/session_018CTvnzcNYmFgm2HQcm821A

Restores the typed class constant in EnvironmentDetector that had to be
reverted under 8.2, and marks the redacting decorators' overrides with
#[Override].

The attribute is not decoration here: a masking leak found earlier today was
exactly a method that no longer matched its parent - ConsoleSectionOutput's
decorated overwrite() path bypassed write() and writeln(), and nothing failed.
With #[Override], a renamed or resignatured Symfony method is a fatal error at
load time instead of output that quietly stops being redacted. Verified by
renaming one override and watching the class refuse to load.

Deliberately not included: typing every existing constant, which would be a
style sweep with no analytical gain, and rewriting withFormatter() as a clone -
8.3 permits reinitialising readonly properties only inside __clone(), which
cannot receive the new value, so the current constructor call stays correct.
@refsz
refsz merged commit 9182ce8 into build/require-php-83 Aug 19, 2026
7 checks passed
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.

1 participant