Skip to content

Route the TableGateway and RowGateway throw sites through named constructors - #193

Merged
simon-mundy merged 4 commits into
php-db:0.6.xfrom
simon-mundy:exception/pr-4-table-gateway
Sep 29, 2026
Merged

simon-mundy merged 4 commits into
php-db:0.6.xfrom
simon-mundy:exception/pr-4-table-gateway

Conversation

@simon-mundy

Copy link
Copy Markdown
Member

Types of changes

  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • QA improvement (unit/integration tests, CS fixes, etc.) that does not change code behavior

Checklist:

  • An issue has been created for this pull request.
  • I have added tests for my changes.
  • All new and existing tests passed.
  • Documentation has been updated accordingly.
  • This pull request targets the correct branch.

Description

PR 4 of 6 from #189: all 36 throw sites in src/TableGateway and src/RowGateway.

Stacked on #190. GitHub cannot base a cross-fork PR on a fork branch, so this targets 0.6.x and shows both commits. Only the second, 27d546dc, belongs to this PR. Merge #190 first; I will rebase after. It does not depend on #191 or #192.

Message text is byte-identical apart from the magic-access messages below, verified template by template against the original literals.

  • 19 templates and factories on TableGateway\Exception\RuntimeException, 4 on its InvalidArgumentException, 5 on RowGateway\Exception\RuntimeException, 2 on its InvalidArgumentException.
  • The four 'The table name of the provided X object must match that of the table' copies collapse onto one template taking the statement name.

PrimaryReplicaFeature is covered. #187 added it and left MasterSlaveFeature delegating to it, so MasterSlaveFeature no longer throws at all. Its first guard reuses MISSING_SQL_INSTANCE; its second reports the primary rather than the master, so MISSING_MASTER_SQL became MISSING_PRIMARY_SQL.

The magic-access messages now name the concrete class. AbstractTableGateway interpolated self::class, so a TableGateway instance reported its abstract parent:

Invalid magic property access in PhpDb\TableGateway\AbstractTableGateway::__get()

All three now carry static::class. This changes the message for every subclass, which is the point. The three tests asserted a substring that excluded the class name, so they passed either way; they now assert the full rendered message against $this->table::class, which fails if the code reverts to self::class.

SequenceFeature was throwing the root PhpDb\Exception\RuntimeException from inside the component, bypassing TableGateway\Exception. It now throws the component type, which extends the root one, so nothing catching the old type breaks.

Test tidy-up in the two files this PR rewrites: the test__call, test__get and test__set methods are renamed to testMagicCall, testMagicGet and testMagicSet forms, and the @codingStandardsIgnore pairs they needed are gone. The stale method-name baseline entries go with them.

Motivation and Context

Refs #189. Depends on #190 for the convention, the constant naming rule and the structural guards.

Nothing here is a BC break. The component exception classes already extended the root ones, and the retypes only narrow within that chain.

How has this been tested?

mago format --check, mago lint and mago analyze all exit 0. Full unit suite passes: 1709 tests, 3608 assertions.

Every factory is covered: 19/19, 4/4, 5/5 and 2/2. All 30 templates verified byte-identical against the original literals by a throwaway script before the call sites were touched.

Baseline and configuration changes

  • The baselined mixed-operand entry on AbstractRowGateway ("Invalid middle operand: type mixed cannot be reliably used in string concatenation") is re-attributed, not added to: the same unsoundness now reports as a mixed-argument against forMissingPrimaryKeyData, count unchanged at 1.
  • src/TableGateway/Exception/ is added to the too-many-methods exclude in mago.toml, as Route the Sql throw sites through named constructors #192 does for src/Sql/Exception/. The threshold is 10 and the catalogue holds 19. This will conflict with Route the Sql throw sites through named constructors #192 on the same line — whichever merges second needs the two paths merged into one array.
  • One halstead reading on AbstractTableGateway is baselined. Removing long string literals reduces distinct operands, which raises halstead difficulty, so simplifying the method moved the metric the wrong way.

@codecov

codecov Bot commented Sep 28, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

…ructors

All 36 throw sites in src/TableGateway and src/RowGateway now call a named
constructor. Message text is byte-identical apart from the magic-access
messages noted below, verified template by template against the originals.

- Add 19 templates and factories to TableGateway\Exception\RuntimeException,
  4 to its InvalidArgumentException, 5 to RowGateway\Exception\RuntimeException
  and 2 to its InvalidArgumentException
- Cover PrimaryReplicaFeature, added by php-db#187. Its first guard reuses
  MISSING_SQL_INSTANCE; its second reports the primary rather than the master,
  so MISSING_MASTER_SQL becomes MISSING_PRIMARY_SQL. MasterSlaveFeature no
  longer throws, since php-db#187 left it delegating to the replacement
- Collapse the four "table name of the provided X object" copies onto one
  template taking the statement name
- Report the concrete class in the magic access messages: AbstractTableGateway
  interpolated self::class, so a TableGateway named its abstract parent. The
  three messages now carry static::class
- Point SequenceFeature at TableGateway\Exception\RuntimeException; it was
  throwing the root PhpDb\Exception\RuntimeException from inside the component
- Rename the test__* methods to testMagicGet, testMagicSet and testMagicCall
  forms and drop the codingStandardsIgnore pairs they needed
- Cover every factory with a template test, and derive the message assertions
  from the templates rather than restating them
- Re-attribute the baselined mixed-operand concatenation entry in
  AbstractRowGateway to the factory that now receives the argument, exclude
  src/TableGateway/Exception/ from too-many-methods, and baseline the halstead
  reading AbstractTableGateway shifts

Signed-off-by: Simon Mundy <simon.mundy@peptolab.com>
@simon-mundy
simon-mundy force-pushed the exception/pr-4-table-gateway branch from 960343b to 61047e7 Compare September 29, 2026 03:34
@simon-mundy simon-mundy added documentation Improvements or additions to documentation qa Improvements in quality assurance of the project RFC RFC issue or PR labels Sep 29, 2026
@github-project-automation github-project-automation Bot moved this to Todo in @phpdb Sep 29, 2026
@simon-mundy simon-mundy added this to the 0.6.0 milestone Sep 29, 2026
@simon-mundy simon-mundy self-assigned this Sep 29, 2026
@simon-mundy
simon-mundy requested a review from tyrsson September 29, 2026 03:45
@simon-mundy
simon-mundy force-pushed the exception/pr-4-table-gateway branch from 468dae9 to fe2d578 Compare September 29, 2026 04:08
@simon-mundy
simon-mundy merged commit 78da839 into php-db:0.6.x Sep 29, 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 enhancement New feature or request qa Improvements in quality assurance of the project RFC RFC issue or PR

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants