Skip to content

refactor: replace type mixed with more specific types#10345

Merged
paulbalandan merged 2 commits into
codeigniter4:developfrom
paulbalandan:mixed-phpdoc-narrowing
Jun 30, 2026
Merged

refactor: replace type mixed with more specific types#10345
paulbalandan merged 2 commits into
codeigniter4:developfrom
paulbalandan:mixed-phpdoc-narrowing

Conversation

@paulbalandan

Copy link
Copy Markdown
Member

Description

Fixes #6310.

Reviews every mixed PHPDoc (and its long-form spelling array|bool|float|int|object|string|null) across system/, and for each one decides whether mixed is appropriate, narrows it when the runtime type is provable, or collapses the verbose union to a plain mixed when the value is genuinely any type. Where the chosen type contains array, key/value information is added (array<int|string, mixed>) instead of a bare array. Split into two commits:

1. Narrowing + array refinements

  • Narrowed mixed to deducible types.
  • Refined bare array to array<key, value> in kept narrower unions.
  • Removed a redundant duplicate @param mixed $condition in ConditionalTrait (the @template-typed tag remains).
  • Left genuinely any-type sites as mixed, and kept PSR-3 / PHPUnit contract params as mixed to honor those interfaces.

2. Collapsing verbose unions

  • Collapsed about 90 long-form array|bool|float|int|object|string|null unions (genuinely any-type) to bare mixed, mostly in Validation/StrictRules, plus Common, Database escape/magic methods, Entity/CastInterface, HTTP request accessors, the array helpers, Model, and View\Parser.
  • Kept precise non-mixed unions: the json_decode stdClass shapes and Parser::objectToArray()'s return, which provably excludes object.
  • Two call sites that relied on the unions being treated as uncertain under treatPhpDocTypesAsCertain: false were made explicit with !== null.

Checklist:

  • Securely signed commits
  • Component(s) with PHPDoc blocks, only if necessary or adds value (without duplication)
  • Unit testing, with >80% coverage
  • User guide updated
  • Conforms to style guide

@paulbalandan paulbalandan changed the title Mixed phpdoc narrowing efactor: replace type mixed with more specific types` Jun 29, 2026
@paulbalandan paulbalandan changed the title efactor: replace type mixed with more specific types` refactor: replace type mixed with more specific types` Jun 29, 2026
@paulbalandan paulbalandan changed the title refactor: replace type mixed with more specific types` refactor: replace type mixed with more specific types Jun 29, 2026
@paulbalandan paulbalandan added the refactor Pull requests that refactor code label Jun 29, 2026
@github-actions github-actions Bot added the stale Pull requests with conflicts label Jun 29, 2026
@github-actions

This comment was marked as resolved.

@paulbalandan paulbalandan force-pushed the mixed-phpdoc-narrowing branch from 7df5bf1 to a5648a3 Compare June 29, 2026 14:22
@paulbalandan paulbalandan removed the stale Pull requests with conflicts label Jun 29, 2026
@paulbalandan paulbalandan merged commit 72476b3 into codeigniter4:develop Jun 30, 2026
56 checks passed
@paulbalandan paulbalandan deleted the mixed-phpdoc-narrowing branch June 30, 2026 03:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

refactor Pull requests that refactor code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Dev: replace type mixed with more specific types

2 participants