Skip to content

[TASK] Upgrade PHPStan ecosystem to 2.x and reduce baseline#1185

Merged
linawolf merged 5 commits intoTYPO3-Documentation:mainfrom
CybotTM:feature/phpstan-2
Mar 1, 2026
Merged

[TASK] Upgrade PHPStan ecosystem to 2.x and reduce baseline#1185
linawolf merged 5 commits intoTYPO3-Documentation:mainfrom
CybotTM:feature/phpstan-2

Conversation

@CybotTM
Copy link
Copy Markdown
Contributor

@CybotTM CybotTM commented Feb 22, 2026

Summary

Coordinated upgrade of the PHPStan ecosystem to major version 2, with baseline reduction by fixing low-hanging fruit type issues.

Package upgrades

Package Old New
phpstan/phpstan ^1.12 ^2.1
phpstan/phpstan-strict-rules ^1.6 ^2.0
symplify/phpstan-rules ^13.0 ^14.9

PHPStan 2.x works on PHP ^7.4|^8.0, no PHP minimum bump needed.

Configuration changes

  • Removed 2 dropped symplify rules (AnnotateRegexClassConstWithRegexLinkRule, RegexSuffixInRegexConstantRule)
  • Renamed strictCallsstrictFunctionCalls (renamed in phpstan-strict-rules 2.x)

Baseline reduction (31 source files fixed)

Instead of just baselining all new errors from PHPStan 2.x's stricter analysis, low-hanging fruit were fixed:

Fix category Entries eliminated
Fix @param on Typo3DocsThemeExtension::load() 15
array_values() wrappers for list<Node> mismatches 12
@phpstan-ignore return.unusedType on interface-mandated return types 9
Cast $input->getArgument() to (string) 3
Fix dead code bug in ConfigureCommand ($guides variable undefined) 4
Various small fixes (casts, annotations, nullsafe cleanup) 4
Total 47 entries eliminated

Baseline: 102 → 55 errors (46% reduction). Remaining entries are complex type narrowing issues (SiteSetSettingsDirective, ViewHelperDirective) that would require DTO refactoring.

Bug fix discovered

ConfigureCommand::operateOnXmlGuides() had a dead code block — the $guides variable was used but never defined. The entire guide attribute modification code was unreachable. Fixed by adding the missing $guides = $xml->xpath('/ns:guides') call.

Test plan

  • vendor/bin/phpstan analyse — 0 errors (with baseline)
  • Unit tests — 83 tests, 183 assertions, all pass
  • Integration tests pass (CI)
  • Quality job passes (CI)

- phpstan/phpstan: ^1.12 -> ^2.1
- phpstan/phpstan-strict-rules: ^1.6 -> ^2.0
- symplify/phpstan-rules: ^13.0 -> ^14.9
- Removed deprecated symplify regex rules (dropped in 14.x)
- Updated strictRules config: strictCalls -> strictFunctionCalls
- Regenerated phpstan-baseline.neon for stricter 2.x rules
@CybotTM CybotTM marked this pull request as draft February 22, 2026 12:04
@CybotTM CybotTM changed the title [TASK] Upgrade PHPStan ecosystem to 2.x [TASK] Upgrade PHPStan ecosystem to 2.x and reduce baseline Feb 22, 2026
Reduce PHPStan baseline from 102 to 55 errors (46% reduction)
across 31 files by applying targeted fixes:

- Fix @param type on Typo3DocsThemeExtension::load() (15 errors)
- Add array_values() wrappers where list<> expected (12 errors)
- Add @phpstan-ignore return.unusedType on NodeTransformers (9 errors)
- Cast $input->getArgument() to (string) in CLI commands (7 errors)
- Fix dead code bug: missing $guides in operateOnXmlGuides() (4 errors)
- Remove unnecessary @var in TwigExtension (2 errors)
- Add @return list<string> to collectUnmigratedLegacySettings() (1 error)
- Cast $errno to (string) in XmlValidator (1 error)
- Fix nullsafe ?->textContent to -> in SiteSetSettingsDirective (1 error)
- Cast $answer to (string) in InitCommand validators (3 errors)
- Add type annotations for return.type entries (3 errors)
- Type-hint RunDecorator process callback parameters (3 errors)
- Cast $_SERVER['argv'] to array in AddThemeSettingsToProjectNode (1 error)
…ssions

Replace inline @phpstan-ignore annotations with genuine code fixes:
- Narrow return types from Node|null to Node (valid PHP covariance)
- Add is_string()/is_array() guards for mixed Symfony Console inputs
- Type-safe extraction of JSON/YAML parsed data with step-by-step validation
- Fix array type annotations (array<string, mixed> instead of array<mixed>)
- Properly handle DOMNodeList access in SiteSetSettingsDirective

Baseline reduced from 41 to 9 entries (vs 13 on main). Remaining 9 are
unfixable external library constraints (phpDocumentor interfaces returning
mixed, Symfony ExtensionInterface contravariance).
… tests

The previous commit incorrectly replaced getValue() with getChildren()
in ViewHelperDirective. These access different properties on CompoundNode
(value vs children), causing the ViewHelper description/examples/sections
to be empty in rendered output.

Restore getValue() with proper is_array() type narrowing to satisfy
PHPStan without changing runtime behavior.
@CybotTM CybotTM marked this pull request as ready for review February 22, 2026 13:47
@linawolf linawolf merged commit a5d9f9b into TYPO3-Documentation:main Mar 1, 2026
9 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.

2 participants