Repository navigation
refactor(types): analyse entity at PHPStan level 8 - #26
Merged
Merged
Conversation
added 4 commits
November 26, 2026 09:49
Value types for the array properties, parameters and returns, and types for the untyped flags, in PHPDoc only: no signature changes.
Correct the @var of the flags and settings whose setters accept null or a boolean, as they behave at run time (also clears the level 8 reports); a null declaration priority falls back to the declared one.
No further change needed after the corrections of level 7.
Also clears the PHPStan reports of that test file, which the fast gates analyse when it changes (two of them were already there at level 5).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Branch
chore/phpstan-level-up, basemain. One commit per level (6, 7, 8), then a test. The baseline (2 entries) is not emptied, and the level was raised anyway: see below.What changes
@varof the properties whose setters acceptnull(or a boolean) now says so (publiclyQueryable,showUi,menuPosition,rewrite,templateLock, ...). These corrections also clear level 8.EntityRegistrationServicepasses$entity->getPriority() ?? $entity->prioritytoadd_action.getPriority()is declared?int; only a subclass override can return null, which used to reachadd_actionas null. This is a guard asked for by the types, not a reported bug;a null declaration priority falls back to the declared priorityfails without it (the test stub ofadd_actionnow records the priority).vendor/bin/pollora-qa ratchet --update(the tool also re-sorts the keys and writes98.0as98).Baseline: blocked by the public API
Both entries are
constructor.unusedParameter: the first constructor argument ofPostTypeService($postTypeRegistry) andTaxonomyService($taxonomyRegistry). The classes are public and not final, and the argument is positional (src/Taxonomy.php, tests, any application that builds them). Removing it breaks every caller, so it needs a major release:@deprecatedin both docblocks and the CHANGELOG/README;src/Taxonomy.php(new TaxonomyService(...)) and in the two service tests;Stopped before level 9
Level 9 reports 15 errors on
src. Some are internal narrowing, but these cannot be satisfied without tightening the documented contract of public ports (PostTypeRegistryPort,TaxonomyRegistryPort,EntityRegistryPort), currentlyarray<array-key, mixed>:register_extended_post_type/register_extended_taxonomy:$namesmust bearray{plural?: string, singular?: string, slug?: string},$objectTypearray<string>|string;register_post_type/register_taxonomy:$argsmust match the WordPress array shape,$slugmust be a non-empty (lowercase) string.The alternative is a validation layer in the adapters that drops values at run time. Both are decisions for the maintainer. The other reports (offsets on
mixed,Entity::getSlug()returningmixed,PostType::$taxonomies) can be fixed with them.Checked (PHP 8.4, macOS)
vendor/bin/phpstan analyselevel 8 (src, the harness paths): 0 errors with the two baselined ones.roave-backward-compatibility-check --from=2.0.0, in a local clone): no backwards-incompatible change.composer qa:fastandcomposer qa: every gate that ran passed. Line coverage 98.86 % (floor 98).tests/Unit/MutationRegistrationTest.php: four PHPStan reports cleared, becauseqa:fastanalyses the changed files (two of them already existed at level 5). Other test files still report when they change.Not verified
composer phpstan(hard-codedsrc tests) was already failing onmain(81 errors at level 5, mostly deprecated-method calls in tests); its level is bumped with the rest and it reports 195 errors at level 8. CI does not run it.