Repository navigation
Issue/612 Convert the first batch of Enums classes to PHP enums - #640
Conversation
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
|
No actionable comments were generated in the recent review.
|
| Layer / File(s) | Summary |
|---|---|
Authentication enum migration src/Auth/Enums/AuthKeys.php, src/Auth/Adapters/*, src/Auth/Traits/AuthTrait.php, tests/Unit/Auth/*, CHANGELOG.md |
AuthKeys is now a string-backed enum. Authentication code uses case values, and tests cover enum values and rejection of a missing user-schema field. |
Database enum contracts and schema operations src/Database/Enums/{Key,Type,TableAction}.php, src/Database/Schemas/*, src/Database/Factories/TableFactory.php, src/Database/Traits/TableTrait.php, tests/Unit/Database/Enums/*, tests/Unit/Database/Schema/* |
Key and Type are string-backed enums, and TableAction is an integer-backed enum. Schema APIs accept enum types, table action constants were removed, and tests cover type errors and SQL output. |
Relation enum and unsupported-relation handling src/Database/Enums/Relation.php, src/Model/Exceptions/ModelException.php, tests/Unit/Database/Adapters/*/Statements/Join*Test.php, tests/Unit/Database/Enums/RelationTest.php |
Relation is now a string-backed enum. unsupportedRelationType accepts a Relation or string, and adapter tests cover unsupported belongs-to-many joins. |
Reserved HTTP keys src/App/Enums/ReservedKeys.php, src/Http/Helpers/http.php, src/Http/Traits/{Request,Response}/*, tests/Unit/App/Enums/ReservedKeysTest.php, tests/Unit/Http/RequestTest.php |
ReservedKeys is now a string-backed enum. HTTP code uses its backed values for request, response, and session keys. |
Pagination enum values and limits src/Paginator/Enums/*, src/Paginator/Traits/PaginatorTrait.php, tests/Unit/Paginator/Enums/* |
Pagination is now a string-backed enum. The numeric pagination limits moved to PaginationLimit, and the paginator uses both definitions. |
Estimated code review effort: 3 (Moderate) | ~25 minutes
Change: Feature
Possibly related PRs
- quantum-php/framework#600: This PR uses native PHP enums, while
#600sets the package and CI PHP version requirements to PHP 8.1 or later. - quantum-php/framework#621: Both PRs change how
Header::back()stores previous-request data usingReservedKeys::PREV_REQUEST.
Suggested labels: enhancement
Suggested reviewers: andrey-smaelov, grigoryanmartin20
Merge Risk: 
Minimal · up to a4bd5
-
The enum migration has no identified issue that needs correction before merge; the documented API changes still require normal compatibility checks.
Pre-merge checks: 
5
-
Full details: Title check
-
Explanation
The title 'Issue/612 Convert the first batch of Enums classes to PHP enums' matches the main change. The PR converts ReservedKeys, AuthKeys, Pagination, Type, Key, and Relation from constant classes to string-backed PHP enums, and adds TableAction and PaginationLimit. The title names the issue and the core change, but does not name the specific classes. It is specific enough for a teammate scanning history.
Full details: Docstring Coverage
-
Explanation
Docstring coverage is 95.45% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 44 functions across 35 files. (1 skipped: 1 unsupported.)
-
Finishing Touches
-
Generate unit tests (beta)
-
- Create a new PR
-
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
Refs #612. This pull request targets
3.1.x, so it does not close the issue; the merge of3.1.xintomasterdoes.What changed
Converts the constant classes that can become enums on PHP 8.1:
ReservedKeys,AuthKeys,Paginationand the databaseType,KeyandRelationare string-backed enums with the same case names and values.Table::CREATE,ALTER,DROPandRENAMEmove to a new int-backedTableActionenum.Paginationkeeps its four names. The numbersFIRST_PAGE_NUMBER,MINIMUM_PAGE_ITEMS_COUNTandEDGE_PADDINGmove toPaginationLimit, an enum that holds them as constants: a backed enum cannot hold them, because two of them are both3.Table::addColumn(),modifyColumn(),Column::__construct(),Table::addIndex()andTable::setAction()take the enum only.AuthTrait::verifySchema()readsAuthKeys::cases()instead ofReflectionClass::getConstants(), andTable::addIndex()chooses the method with amatchoverKey.ModelException::unsupportedRelationType()accepts aRelationor text.Why
An enum gives a closed set of values that PHP and PHPStan check, instead of free strings and integers. The adapter types,
StatusCode,ContentType,Env,ExitCodeand theExceptionMessagesclasses stay constant classes (see #620).Breaking changes
Yes, listed in
CHANGELOG.mdwith the migration note:stringparameters need->value.addColumn(),modifyColumn(),new Column(),addIndex()orsetAction()throws aTypeError.Table::CREATE,ALTER,DROPandRENAMEare removed.typemust be aRelationcase.TableorColumnthat overrides the changed methods must declare the enum types.Relation::BELONGS_TO,Type::INTandKey::INDEXare written as before, so the module templates and migrations that use them need no change.Testing
addColumn,modifyColumn,Column,addIndex,setAction), a test for everyKeythroughaddIndex()and the generated SQL, and tests thatbelongsToManyis reported as unsupported by both join adapters.Request::set()and one for a user schema with a missing key inSessionAuthAdapter, which had no coverage.Notes for reviewers
PaginationLimitis a new name for the three numbers.Summary by CodeRabbit
Tableare no longer available.TypeError.