Repository navigation
Bring Mago back to green against phpdb 0.6.x - #44
Open
simon-mundy wants to merge 3 commits into
Open
simon-mundy wants to merge 3 commits into
simon-mundy wants to merge 3 commits into
Conversation
Driver::createResult() called columnCount() on a resource documented as PDOStatement|resource, and getLastGeneratedValue() on a connection that may be a raw PDO. The row counter is now only consulted for a PDOStatement, and the last generated value is read through AbstractPdo::getLastGeneratedValue(), which delegates to the connection. SqliteRowCounter fetched the count from PDO::query() (PDOStatement|false) and from a result resource typed as mixed. Both paths now go through a private fetchCount() that requires a PDOStatement and throws a RuntimeException otherwise. The thrown exceptions are documented on the public methods and on the row count closure. Tests cover the row counter for SQL and statement contexts, the failure paths, and how createResult() wires the row counter and generated value. Baseline entries made obsolete by these changes are removed or reduced.
The column, constraint, table and trigger loops used the mixed name from each row as an array key, which the analyzer reports as an invalid index type. The names are now cast to string. The cached arrays still carry keys that phpdb's MetadataData shapes do not declare, so the five baselined property-type-coercion entries for these assignments are now reported as mixed-property-type-coercion and invalid-property-assignment-value. Their baseline entries are replaced one for one; typing the rows properly is left to the analyzer cleanup.
On PHP 8.4 and later the formatter dropped the parentheses in (new ConfigProvider())(), which PHP 8.3 cannot parse. mago.toml now sets parentheses-around-new-in-member-access, as phpdb and phpdb-mysql do. phpdb 0.6.x removed VunerablePlatformQuoteException; quoting without driver support now throws Adapter\Exception\RuntimeException with the same message. The parent class the old exception extended is expected instead, with the message, so the test passes against both versions.
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues remain for the SQLite adapter compatibility and Mago updates.
No open issues 🎉
What changed in this PR
This PR updates the SQLite adapter for phpdb 0.6.x compatibility and restores Mago checks, leaving broader driver and baseline cleanup to follow-up PRs.
Changes:
- Guards PDO statement access, delegates generated-value retrieval through the driver, and centralizes count-query validation.
- Casts metadata cache keys to strings and updates Mago configuration and baselines.
- Expands driver and row-counter tests and aligns quoting-exception expectations with phpdb.
| File | Description |
|---|---|
test/unit/Pdo/Feature/SqliteRowCounterTest.php |
Covers count queries, failure handling, and row-count closures. |
test/unit/Pdo/DriverTest.php |
Adds generated-value and row-counter selection tests. |
test/unit/AdapterPlatformTest.php |
Updates expected quoting exceptions and messages. |
src/Pdo/Feature/SqliteRowCounter.php |
Shares count fetching, validates statements, and documents exceptions. |
src/Pdo/Driver.php |
Guards columnCount() and uses driver-level generated-value retrieval. |
src/Metadata/Source.php |
Casts column, constraint, table, and trigger cache keys to strings. |
mago.toml |
Configures parentheses around new expressions used in member access. |
lint-baseline.toml |
Removes or reduces entries resolved by the changes. |
analyzer-baseline.toml |
Updates metadata diagnostics and reduces row-counter baseline entries. |
Review effort: Balanced
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.
Mago fails on this branch against current phpdb 0.6.x. This makes it pass again. It is the first of the driver cleanup PRs; the analyzer and lint baselines are reduced in follow-ups.
Changes
Pdo\Driver::createResult():columnCount()is only called when the resource is aPDOStatement.getLastGeneratedValue(), which passes the call to the connection. Before, it was called on the raw PDO.Pdo\Feature\SqliteRowCounter: both count paths now fetch through a privatefetchCount(). It throwsPhpDb\Adapter\Exception\RuntimeExceptionwhen the count query does not produce aPDOStatement; before,fetch()was called onfalse. Its@throwsare documented.Metadata\Source: the column, constraint, table and trigger caches are keyed by the name cast to string.Baselines
constraint_nameandtrigger_name) that phpdb'sMetadataDatashapes do not declare. So the fiveproperty-type-coercionentries for those assignments are now reported as threemixed-property-type-coercionand twoinvalid-property-assignment-value, and their baseline entries are swapped for the new wording. Typing the rows properly is left to the analyzer cleanup.Tests
The
SqliteRowCountertests are rewritten to cover every path, andcreateResult()tests are added to thePdo\Drivertests.Verification
mago fmt --dry-run,lint,analyzeandguardall exit 0. The unit suite passes (110 tests), and so does the integration suite (18 tests).