Repository navigation
fix(session): inherit the parent type for Insert::$specifications - #26
Merged
Merged
Conversation
`PhpDb\Session\Sql\Insert` overrode `$specifications` with `@var array[]|string[]`, which is incompatible with the parent property's `array<string, Specification>`. PHP requires property types to be invariant, so `mago analyze` reported `incompatible-property-type` once php-db/phpdb declared the parent type at 1570a612. The override is dropped so the property inherits the parent declaration. The assigned values are plain strings, which satisfy the parent type.
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
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.
Symptom
Renovate PR #25 (lock file maintenance) moves the dev dependency
php-db/phpdbfromed4a407c2f51b951e0261da0bf93baacb23d2e98to1570a6122cde75699394a6a38cf17335c3b1d622on0.6.x. BothMago (PHP 8.4)andMago (PHP 8.5)then failmago analyzewith:Root cause
At
1570a612,php-db/phpdbsrc/Sql/Insert.phpdeclares the property as@var array<string, Specification>, whereSpecification = string|array<string, list<ParameterSpecification>>is a psalm type alias defined onphp-db/phpdbsrc/Sql/AbstractSql.php.webware-phpdbsrc/Session/Sql/Insert.phpoverrode the same property with the looser@var array[]|string[]. PHP requires property types to be invariant, so the two declarations cannot coexist.Fix
The
@varoverride is removed, so the property inherits the parent declaration. The values assigned here are plain strings, which satisfy the parent type, so nothing about runtime behaviour changes.Why this form: the override documented nothing the parent does not already say. The two more explicit alternatives were tested against both lock states:
ed4a407(this branch's lock)1570a612(PR #25)@var array<string, Specification>plus@import-type Specification from AbstractSqlinvalid-import-type: the alias does not exist ated4a407array<string, string|array<string, list<array<int|string, string>|null>>>ed4a407isstring[]|array[]@var(this PR)Removing the override is the only form that is green before and after the lock bump.
Gates
Run locally with mago 1.59.0 on PHP 8.5.12, against the committed lock (
ed4a407):mago format --check: passmago lint: passmago analyze: pass, 0 errors (4 warnings and 4 help messages, all pre-existing)mago guard: passSchemaFactoryIntegrationTest::itCreatesPrefixedTableOnPgsqlerrors withcould not find driver, becausepdo_pgsqlis not installed in this environment. Unrelated to this change.With
vendor/php-db/phpdbswapped to1570a612, theincompatible-property-typefindings for this class are gone.Out of scope
The same analyze run at
1570a612reports 11 further errors that this change does not touch:unhandled-thrown-type(PhpDb\Sql\Exception\RuntimeException) inInitDbCommand::executeDdl,DbSessionHandler::{destroy,gc,read,write}andPhpDbSessionPersistence::{initializeSessionFromRequest,persistSession,destroy}possible-method-access-on-nullinDbSessionHandlerlines 98 and 121, andPhpDbSessionPersistenceline 134Those appear only because the newer phpdb declares that exception and narrows the affected return types. They are a separate defect exposed by the same lock refresh, and PR #25 will stay red on
mago analyzeuntil they are fixed.Also at
1570a612, the singleanalysis-baseline.tomlentry (a vendoruninitialized-propertyinPhpDb\TableGateway\Feature\AbstractFeature) no longer matches, so mago reports it as outdated. That baseline is left untouched here.