Skip to content

Bring Sql\Ddl to Mago compliance - #231

Merged
simon-mundy merged 4 commits into
php-db:0.6.xfrom
simon-mundy:qa/mago-sql-ddl
Oct 12, 2026
Merged

simon-mundy merged 4 commits into
php-db:0.6.xfrom
simon-mundy:qa/mago-sql-ddl

Conversation

@simon-mundy

Copy link
Copy Markdown
Member

Takes Sql\Ddl out of the lint baseline entirely and leaves 3 of its 62 analyzer findings, and fixes a TypeError in getRawState() along the way.

Stacked on #230 (Predicate), which is stacked on #229 (baseline refresh). Only the last two commits are new here.

Bug fixed

AlterTable::getRawState() and CreateTable::getRawState() declared array|string. Asking for the table of a statement built with a TableIdentifier therefore threw:

(new AlterTable(new TableIdentifier('t', 's')))->getRawState(AlterTable::TABLE);
// TypeError: Return value must be of type array|string, PhpDb\Sql\TableIdentifier returned

Both now declare TableIdentifier as well, and describe the raw state with a RawState shape.

Cleanup

  • The DDL process*() methods take a PlatformInterface, not ?PlatformInterface = null. buildSqlString() always passes one, and the phpdb-mysql decorators already cast it to non-null. Their ?PlatformInterface overrides stay compatible, because a wider parameter type in a child is allowed.
  • CreateTable::processCombinedby() returns an empty parameter list rather than reading the separator back out of $specifications. processStatementEnd() drops the platform parameter it never used.
  • AlterTable builds its column, constraint and index lists with array_map instead of five hand-written loops. This clears its kan-defect.
  • The column constructors type $default as the values setDefault() accepts, where they used to take mixed, and Column::$default now starts as null. Constructors are exempt from signature compatibility, so subclasses are unaffected.
  • ForeignKey::$referenceSpecification is typed as the two-part shape getExpressionData() reads.
  • AbstractPrecisionColumn::getLengthExpression() is a single match, which clears its halstead finding.
  • Every class and interface in the component is tagged @api, not made final, as in Bring Sql\Predicate to full Mago compliance #230.
  • In mago.toml, AlterTable and CreateTable join the too-many-methods exclusions as fluent builders. ForeignKey and AbstractPrecisionColumn are excluded from excessive-parameter-list: their public constructors take one argument per part of the definition they model.

Left for the DML pass

Three findings remain, one per processTable(). They trace back to AbstractSql::resolveTable() declaring string|array|null. Only Select's override returns an array; it reuses the name for a different [table, fromTable] shape. Fixing that is a Select change, so it belongs with the DML PR.

Result

Before (#230) After
Lint baseline (issues) 222 216
Analyzer baseline (issues) 697 638
src/Sql/Ddl in either baseline 68 3
PHPUnit 2154 tests 2156 tests

Line and method coverage of src/Sql/Ddl is 100%. Infection reports 100% covered-code MSI: 287 killed and 5 caught by static analysis.

@codecov

codecov Bot commented Oct 11, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

AlterTable::getRawState() and CreateTable::getRawState() declared
array|string, so asking either for the table of a statement built with
a TableIdentifier threw a TypeError. Both now declare TableIdentifier
too, with the raw state described by a RawState shape.

The DDL processors take PlatformInterface rather than a nullable
platform defaulting to null. buildSqlString() always passes one, and
the platform packages' decorators already cast it to non-null. Their
?PlatformInterface overrides stay compatible.

processCombinedby() returns an empty parameter list instead of reading
its separator back out of the specifications, and processStatementEnd()
drops the platform it never used. AlterTable maps its column, constraint
and index lists instead of looping over each by hand.

The column constructors type $default as the values setDefault()
accepts, and Column::$default starts as null. ForeignKey's reference
specification is typed as the two-part shape getExpressionData() reads.
Every DDL statement, column, constraint and index class is public API
that the platform packages extend, so each is marked @api rather than
final, as in Sql\Predicate.

AlterTable and CreateTable join the too-many-methods exclusions as
fluent builders. ForeignKey and AbstractPrecisionColumn are excluded
from excessive-parameter-list: their constructors take one argument per
part of the definition they model and are public API.

Three findings stay baselined, one per processTable(). They come from
AbstractSql::resolveTable() declaring an array return that only
Select's override produces, and belong with the DML pass.
@simon-mundy
simon-mundy requested a review from tyrsson October 11, 2026 23:44
@simon-mundy simon-mundy self-assigned this Oct 11, 2026
@simon-mundy simon-mundy added bug Something isn't working documentation Improvements or additions to documentation enhancement New feature or request qa Improvements in quality assurance of the project labels Oct 11, 2026
@simon-mundy simon-mundy added this to the 0.6.0 milestone Oct 11, 2026
@simon-mundy
simon-mundy marked this pull request as ready for review October 11, 2026 23:46
tyrsson
tyrsson previously approved these changes Oct 12, 2026
@github-project-automation github-project-automation Bot moved this from Todo to In Progress in @phpdb Oct 12, 2026
@simon-mundy
simon-mundy dismissed tyrsson’s stale review October 12, 2026 02:23

The merge-base changed after approval.

@simon-mundy
simon-mundy merged commit 9d4f906 into php-db:0.6.x Oct 12, 2026
15 checks passed
@github-project-automation github-project-automation Bot moved this from In Progress to Done in @phpdb Oct 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working documentation Improvements or additions to documentation enhancement New feature or request qa Improvements in quality assurance of the project

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants