Repository navigation
Clear Mago findings in the Sql platform layer - #252
Open
simon-mundy wants to merge 1 commit into
Open
simon-mundy wants to merge 1 commit into
simon-mundy wants to merge 1 commit into
Conversation
Platform and AbstractPlatform called getSqlString() and prepareStatement()
on whatever getTypeDecorator() returned, typed as
PlatformDecoratorInterface|PreparableSqlInterface|SqlInterface. Neither
PlatformDecoratorInterface nor the opposite Sql interface declares those
methods, so a decorator registered for a type it does not render ended in
an "undefined method" Error. The result is now narrowed with instanceof at
the call site and a named RuntimeException (forDecoratorNotImplementing)
is thrown instead. PlatformDecoratorInterface itself is unchanged, so
third-party decorators are not affected.
AbstractPlatform::$subject is now nullable with a null default, matching
PlatformDecoratorInterface::setSubject(), which accepts null. Using a
cleared or never-set subject now raises the existing "subject does not
implement" RuntimeException instead of a TypeError or an uninitialised
property Error.
Platform::getDecorators() returns an empty list when nothing is
registered for the default platform, instead of an undefined-key warning
followed by a TypeError. The decorator map is documented, and Platform
reads it through one private accessor.
PlatformDecoratorInterface is marked @api. AbstractSql's runtime
process{Name}() dispatch, subject state copy, class size and protected
processExpressionOrSelect() signature are recorded as @mago-expect,
since changing them would break subclasses.
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.
Problem
Sql\Platform\PlatformandAbstractPlatformcallgetSqlString()andprepareStatement()on whatevergetTypeDecorator()returns. That method's return type isPlatformDecoratorInterface|PreparableSqlInterface|SqlInterface.PlatformDecoratorInterfacedeclares neither method, and each Sql interface lacks the other's, so Mago reportsnon-existent-method. At runtime, a decorator registered for a type it cannot render ends in a fatal "Call to undefined method" error.There are related gaps in the same layer:
AbstractPlatform::$subjectis non-nullable with no default, althoughsetSubject()acceptsnull.Platformstores a nested map in it.Platform::getDecorators()reads an undefined key when no decorators are registered for the default platform.PlatformDecoratorInterfacehas no@apitag.Fix
instanceof, through onefinal protectedhelper onAbstractPlatformthatPlatformreuses. If the decorator doesn't implement the needed interface, the helper throws a new named exception,Sql\Exception\RuntimeException::forDecoratorNotImplementing().PlatformDecoratorInterfaceis unchanged, so third-party decorators keep working.AbstractPlatform::$subjectis nowSqlInterface|PreparableSqlInterface|null = null, matchingsetSubject().Platformreads it through one private accessor that defaults to[].PlatformDecoratorInterfaceis tagged@api.AbstractSqlhas six findings that cannot be fixed without changing signatures subclasses depend on. They are now recorded inline with@mago-expectand a reason, following the existing pattern inFeatureSetandAbstractSource:process{Name}()is dispatched by a name built at runtime;processExpressionOrSelect()signature.What stays the same
PlatformDecoratorInterfaceand all public and protected method signatures.instanceofmatch.Platformstays non-final, and itsclass-must-be-finalfinding stays baselined.Behaviour changes (fail-closed)
Sql\Exception\RuntimeException, instead of a fatal error.RuntimeException, instead of aTypeError.Platform::getDecorators()returns[]when no decorators are registered, instead of a warning followed by aTypeError.BC note: a subclass that redeclares
$subjectwith the old non-nullable type would need to widen it. None of the first-party driver packages do.Verification
mago format --check,lint,analyzeandguardexit 0 on PHP 8.3, 8.4 and 8.5, with no stale baseline entries.srcline is covered.getDecorators()with nothing registered;setTypeDecorator()keeping existing entries.