Skip to content

Clear the non-BC Mago findings in Container, Adapter and ResultSet - #253

Open
simon-mundy wants to merge 2 commits into
php-db:0.6.xfrom
simon-mundy:qa/mago-src-types
Open

simon-mundy wants to merge 2 commits into
php-db:0.6.xfrom
simon-mundy:qa/mago-src-types

Conversation

@simon-mundy

Copy link
Copy Markdown
Member

Problem

About 55 Mago findings in src/Container, src/ConfigProvider.php, src/Adapter and src/ResultSet sit in the baselines. They cover:

  • missing or imprecise types;
  • mixed values;
  • nullable array access;
  • container exceptions that aren't declared with @throws;
  • redundant docblocks;
  • isset() / empty() use.

Fix

  • Types: precise docblock types for the container config arrays, the factory options, __set_state()'s state and the ConfigProvider arrays.
  • Exceptions: @throws for the container exceptions each factory and canCreate() can raise.
  • Docblocks: redundant @var docblocks are removed from built services and result-set rows. One of them was wrong (ResultSetInterface|null).
  • canCreate() uses an equivalent is_array() / [] !== check instead of isset() / empty().
  • The abstract factory reads the named adapter config once, null-safe.
  • RowPrototypeResultSet::toArray() iterates through its nullable current(). The analyzer flagged the old instanceof check as redundant, but null rows really do occur, so the null-row passthrough is now typed instead.
  • AdapterInterfaceFactory reports a missing driver with ContainerException::forMissingDriver(), as the abstract factory already does, instead of a TypeError from ServiceManager::build().
  • Baselines: the analyzer baseline goes from 284 to 244 issues, and the lint baseline from 153 to 151.

What stays the same

  • No public or protected signature changes.
  • No native types added to non-final classes or interfaces.
  • Findings that need a BC change stay baselined, for a separate decision:
    • native property and return types on @api classes and interfaces;
    • AbstractPdo::getResultPrototype()'s nullability.
  • Class-design and complexity findings also stay baselined.
  • Behaviour is unchanged apart from the missing-driver exception.

Verification

  • mago format --check, lint, analyze and guard exit 0 on PHP 8.3, 8.4 and 8.5.
  • The full PHPUnit suite passes.
  • Every changed src line is covered.
  • Infection finds no escaped mutants on changed lines.
  • New tests cover:
    • the configs canCreate() rejects;
    • which config key the adapter is read from first;
    • the missing driver;
    • null rows in toArray().

Give the config arrays and factory options precise docblock types,
document the container exceptions each factory can raise, drop the
redundant @var casts on built services, replace isset/empty in
canCreate() with an equivalent is_array check, and mark the unused
delegator $options parameter as expected.

AdapterInterfaceFactory now throws ContainerException::forMissingDriver()
when the adapter configuration has no driver, matching the abstract
factory, instead of passing null to ServiceManager::build() and failing
with a TypeError.

Remove the baseline entries these changes clear.
Mark the rows read for field counting as mixed, drop the @var object
casts the analyzer already infers in toArray(), and have
RowPrototypeResultSet::toArray() iterate through current(), whose
nullable return type makes the null-row passthrough explicit rather
than a redundant instanceof check. Document the exceptions that
iteration can raise.

Remove the baseline entries these changes clear.
@codecov

codecov Bot commented Nov 17, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

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