Repository navigation
Widen ConnectionInterface::getResource() to resource|object|null - #227
Merged
Merged
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
mago 1.52.0 changed method-name casing in non-existent-method messages (getlastgeneratedvalue -> getLastGeneratedValue, getsqlstring -> getSqlString, preparestatement -> prepareStatement), so the 11 baselined entries for Pdo/AbstractPdo.php and Sql/Platform/* stopped matching and resurfaced. Regenerated with mago analyze --generate-baseline under 1.52.0. The diff is exactly 11 message lines: no entries added, none removed, no findings changed.
simon-mundy
approved these changes
Oct 8, 2026
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.
What
ConnectionInterface::getResource()declares@return resource, but no implementation can honour it.AbstractConnection::getResource()is annotated@return resource|null, andAbstractConnection::disconnect()assigns$this->resource = null, sonullis a legitimate and reachable return value. The interface's@return resourcewas simply wrong about its own contract, and the mismatch was already live on0.6.x.Two changes:
ConnectionInterface::getResource()->@return resource|object|null.Returns are covariant, so widening the interface legalises the narrower
@return resource|nullalready declared byAbstractConnectionandPdo\AbstractPdoConnection. Theobjectarm is required becausemysqlihas been an object since PHP 8.1 -- the mysqli driver's connection is not aresource.AbstractConnection::$resource-- drop the@var mixeddocblock.It was redundant (
mixedis the implicit type) and actively harmful: it forced subclasses that declare their real type to be reported asincompatible-property-type. The prose "Extending classes must be covariant" is kept as a comment.No native types are added, so runtime behaviour is unchanged.
Effect on the baseline
Baselines are generated by mago, never hand-edited -- these were pruned with
mago analyze --remove-outdated-baseline-entries.analyzer-baseline.tomlgoes 716 -> 713 blocks;lint-baseline.tomlis unchanged.Three findings are un-suppressed because they no longer exist:
src/Adapter/Driver/AbstractConnection.phpincompatible-return-typenull|resourcevs parentresourcesrc/Adapter/Driver/AbstractConnection.phpincompatible-return-typePdo\AbstractPdoConnection::getresource()src/Adapter/Driver/Pdo/AbstractPdoConnection.phpincompatible-property-type$resourcedocblock incompatible with parentNothing else was dropped -- verified by diffing the baseline before and after.
missing-property-typeandmixed-return-statementonAbstractConnection::$resourcedeliberately remain: the property is genuinely still untyped, and giving it a real shape is a separate decision.Gates
mago format --check,mago lintandmago analyzeare all clean (no guard config in this repo).vendor/bin/phpunit --testsuite "unit test"-- 2089 tests, 4038 assertions, OK.Consumer verification
Verified against
phpdb-mysqlby temporarily aliasing this clone in as a Composerpathrepository (junction + mago path), then reverting the scaffolding. Measured A/B against the same phpdb commit so the delta could not confound the result:phpdb-mysql.phpdb-mysql's baselined entries become outdated -- the inherited$resourcecontract findings this change clears.phpdb-mysql's 193 unit tests pass against this branch.A fourth
phpdb-mysqlentry (SelectDecorator::$specifications) is also reported as outdated when resolved against the current0.6.xtip, but it is unrelated to this change and is not pruned here.Follow-up
phpdb-mysql'scomposer.lockstill pinsb57f549, which is 270 commits behind0.6.x. Its CImagojob installs from that lock, so thephpdb-mysqlside of this contract change will be pruned once that lock is synced.