Skip to content

Build statements from the platform instead of decorating them - #88

Open
tyrsson wants to merge 5 commits into
0.5.xfrom
rfc/256-statement-factory
Open

tyrsson wants to merge 5 commits into
0.5.xfrom
rfc/256-statement-factory

Conversation

@tyrsson

@tyrsson tyrsson commented Nov 27, 2026 •

Copy link
Copy Markdown
Member

Companion to php-db/phpdb#258, which moves statement construction onto the platform. This is the driver half of the change.

  • Sql\Select, Sql\Ddl\CreateTable and Sql\Ddl\AlterTable replace SelectDecorator, CreateTableDecorator and AlterTableDecorator. They are plain subclasses of the standard statements and no longer implement PlatformDecoratorInterface or hold a subject.
  • Sql\Platform overrides the three factory methods whose statements mysql renders differently and returns those classes. The remaining statements come from the standard factory unchanged.
  • AdapterPlatform::getSqlPlatformDecorator() becomes getStatementFactory().
  • Select::prepareSpecifications() replaces the localizeVariables() override, which only existed to run after the subject copy. The offset-without-limit specification rewrite is unchanged.
  • Connection::$resource is declared mixed to match AbstractConnection, which phpdb 0.6.x typed. The untyped property is a fatal error against that release, so it also fixes installing this package against phpdb 0.6.x.
  • php-db/phpdb resolves from the phpdb branch until #258 is released, at which point the repositories entry and the constraint revert.

Why: the dialect is known when the platform is selected, so the statement can be built as its dialect class instead of being copied into a decorator at render time.

The first commit brings the tree in line with Mago 1.61.

Mago 1.61 code changes

src/Connection.php:128 redundant-docblock-type

-        /** @var string|null $hostname */
         $hostname = $findParameterValue(['hostname', 'host']);

src/Driver.php:81 incompatible-parameter-type

-     * @param mysqli|mysqli_stmt|string $sqlOrResource
+     * @param mysqli_stmt|string|null $sqlOrResource A prepared mysqli_stmt to wrap, or the SQL to prepare

The finding it still raises is the analyzer's model of the mysqli resource, and is baselined beside the existing createResult entry.

src/Metadata/Source.php:52, 145, 265, 320, 376, 479, 554 invalid-argument, imprecise-type

-        array_walk($isColumns, static function (&$c) use ($p) {
-            $c = $p->quoteIdentifierChain($c);
-        });
+        $isColumns = array_map($p->quoteIdentifierChain(...), $isColumns);

554 calls quoteIdentifier rather than quoteIdentifierChain.

src/Metadata/Source.php:98 possibly-undefined-int-array-index, possibly-null-argument

-                    ? str_replace("''", replace: "'", subject: $matches[1])
+                    ? str_replace("''", replace: "'", subject: $matches[1] ?? '')

tyrsson and others added 2 commits November 26, 2026 22:24
The formatter moves with 1.61. The metadata source quotes its column and constraint lists with
array_map instead of an array_walk that the analyzer cannot follow through the by-reference
callback, and reads the permitted values from a match that is known to exist, so the implode and
array-index findings go away. The redundant hostname docblock is gone, and the createStatement
docblock no longer claims an mysqli instance, which the parameter does not require.

The two remaining findings are the analyzer's model of the mysqli resource, which cannot express
the driver's createStatement and getResource contract; they are baselined, as the sibling
createResult finding already was.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The decorators become plain statement subclasses. Sql\Platform returns them from the factory
methods whose statements mysql renders differently, so Select, CreateTable and AlterTable carry
the dialect from construction, and AdapterPlatform exposes the factory through
getStatementFactory().

Select keeps the offset-without-limit specification rewrite in prepareSpecifications(), which
replaces the localizeVariables() override that existed to wrap the subject copy.

Connection::\ is declared mixed to match AbstractConnection, which phpdb 0.6.x typed;
the untyped property was a fatal error against that release. The analyzer baseline is regenerated
against the new dependency.

php-db/phpdb resolves from the companion phpdb branch until it is released.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@codecov

codecov Bot commented Nov 27, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 93.33333% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/Metadata/Source.php 87.50% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

tyrsson and others added 3 commits November 26, 2026 23:23
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant