Skip to content

Replace else branches in Sql with guard clauses and match - #220

Merged
simon-mundy merged 5 commits into
php-db:0.6.xfrom
simon-mundy:qa/mago-sql-guard-clauses
Oct 9, 2026
Merged

simon-mundy merged 5 commits into
php-db:0.6.xfrom
simon-mundy:qa/mago-sql-guard-clauses

Conversation

@simon-mundy

Copy link
Copy Markdown
Member

Depends on #219. Until the earlier PRs in this series merge, this diff also shows their commits; the change here is the last commit, "Replace else branches in Sql with guard clauses and match".

Clears all 53 no-else-clause Mago lint findings in src/Sql.

Changes

  • If/elseif chains that pick a value become match (true) expressions: option rendering in AlterTable and CreateTable, argument wrapping in Expression, In, Operator and PredicateSet, join names in AbstractSql::processJoin(), and column aliases and order direction in Select.
  • Other branches return or continue early instead: the where() and having() setters, Insert::values(), the bound-parameter loops in Insert and Update, Select::group() and Select::order(), and AbstractSql::resolveTable().
  • AbstractSql gains a private quoteJoinTableIdentifier(), so processJoin()'s match stays flat.
  • New tests cover a join on a TableIdentifier without a schema, and resolveTable() with a null or empty table. Neither path had a test.
  • Lint and analyzer baselines are regenerated; only src/Sql entries change.

Breaking changes

None.

mago format, mago lint, mago analyze and the unit tests pass, and every changed line is covered.

Value-picking if/elseif chains become match (true) expressions and the
rest return or continue early. AbstractSql gains a private helper that
quotes a join's TableIdentifier, which keeps processJoin's match flat.

Cover the join path for a TableIdentifier without a schema and the
resolveTable path for an empty table, neither of which had a test.

Signed-off-by: Simon Mundy <simon.mundy@peptolab.com>
@codecov

codecov Bot commented Oct 4, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@simon-mundy simon-mundy added documentation Improvements or additions to documentation qa Improvements in quality assurance of the project Lang Feature Refactor Refactoring to new language features labels Oct 4, 2026
@github-project-automation github-project-automation Bot moved this to Todo in @phpdb Oct 4, 2026
@simon-mundy simon-mundy added this to the 0.6.0 milestone Oct 4, 2026
@simon-mundy simon-mundy self-assigned this Oct 4, 2026
@simon-mundy
simon-mundy requested a review from tyrsson October 6, 2026 02:20
@simon-mundy
simon-mundy marked this pull request as ready for review October 6, 2026 02:20
tyrsson
tyrsson previously approved these changes Oct 8, 2026
@simon-mundy
simon-mundy merged commit 6e93cd9 into php-db:0.6.x Oct 9, 2026
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation Lang Feature Refactor Refactoring to new language features qa Improvements in quality assurance of the project

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants