Improve Sql class to work with shape detection#98
Conversation
There was a problem hiding this comment.
Pull request overview
This PR replaces the previous string/dispatch-table SQL builder with a shape-detection–based Sql builder, updating consumers and tests to use triplet-style conditions and new query composition.
Changes:
- Reworked
Sqlinto a shape-based__call/__callStaticdispatcher supporting triplet conditions, list formatting, raw expressions, andconcat()composition. - Updated
MapperandDbto use the new builder patterns (triplet conditions,concat(), and removal ofDb::query()). - Rewrote/expanded tests to cover the new condition syntax, subqueries, raw expressions, and DDL/DCL builders.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
src/Sql.php |
New shape-detection SQL builder implementation (lists, triplets, raw, concat, expand operators). |
src/Mapper.php |
Migrates Mapper query construction to triplet conditions and new builder APIs. |
src/Db.php |
Removes the raw SQL query() escape hatch and relies on fluent SQL builder usage. |
tests/SqlTest.php |
Updates and expands test coverage for the new Sql API and syntax. |
tests/DbTest.php |
Updates Db tests to avoid query() and use fluent builder with triplet conditions. |
tests/MapperTest.php |
Updates fixture inserts to new insert API and adjusts condition-based fetch tests. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
Replace the old Sql builder with a shape-detection architecture that auto-detects SQL clause type from argument structure instead of relying on method-name dispatch tables and string concatenation. Conditions now use explicit triplet syntax ['column', 'operator', value] with inline 'AND'/'OR' operators and nested grouping via arrays, replacing the old associative-array-with-operator-in-key convention and the underscore grouping methods (and_/or_/_). Key changes in src/Sql.php: - Shape-based __call dispatch into named private methods (commaList, namedList, rawPairs, paramPairs, valueList, conditions) - Triplet condition rendering (scalarTriplet, subqueryTriplet, expandTriplet) with declarative EXPAND constant for IN/NOT IN/BETWEEN - RAW constant for instructions where assoc values are identifiers (on) - Sql::raw() for unparameterized expressions (NOW(), counter + 1) - concat() replaces appendQuery() for query composition - Structured column definitions ['id', 'INT', 'PRIMARY KEY'] in DDL - Full PHPStan compliance with no mixed, no @var inlines, no ignores Key changes in consumers: - Db: removed query() raw SQL escape hatch - Mapper: triplet conditions in parseConditions/guessCondition, array_keys/array_values split for insertInto/values, spread operator for select, concat() for extra clauses - Tests rewritten for triplet syntax with expanded coverage (IN, BETWEEN, NOT IN, subqueries, raw expressions, DDL, DCL)
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #98 +/- ##
============================================
- Coverage 98.63% 98.09% -0.54%
- Complexity 192 200 +8
============================================
Files 3 3
Lines 513 526 +13
============================================
+ Hits 506 516 +10
- Misses 7 10 +3 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Replace the old Sql builder with a shape-detection architecture that auto-detects SQL clause type from argument structure instead of relying on method-name dispatch tables and string concatenation.
Conditions now use explicit triplet syntax ['column', 'operator', value] with inline 'AND'/'OR' operators and nested grouping via arrays, replacing the old associative-array-with-operator-in-key convention and the underscore grouping methods (and_/or_/_).
Key changes in src/Sql.php:
Key changes in consumers: