refactor: change magic model methods to camelCase#19
Merged
davebarnwell merged 3 commits intomainfrom Mar 7, 2026
Merged
Conversation
There was a problem hiding this comment.
Pull request overview
Refactors the ORM’s dynamic static model method handling to make camelCase the canonical public API while keeping legacy snake_case methods working with deprecation notices, and updates tests/fixtures accordingly.
Changes:
- Refactored
Model::__callStatic()to parse/dispatch dynamic finder/counter methods via a single path, emittingE_USER_DEPRECATEDfor snake_case variants. - Updated internal
Model::find()to avoid constructingfind_by_<field>dynamically (removing internal reliance on snake_case dynamic methods). - Updated test fixture annotations and PHPUnit coverage to prefer camelCase methods, adding a regression test for camelCase lookup against snake_case DB columns.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
src/Model/Model.php |
Centralizes dynamic static method parsing/dispatching; adds snake_case deprecation warnings; refactors find() to avoid deprecated dynamic method construction. |
tests/Model/CategoryTest.php |
Switches tests to camelCase dynamic methods; adds regression test for updated_at; adds deprecation-capture helper and legacy-compat assertions. |
test-src/Model/Category.php |
Updates PHPDoc @method annotations to camelCase as the primary contract and notes legacy snake_case support. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This change makes camelCase the canonical naming scheme for the models dynamic static methods while keeping the legacy snake_case forms working during the transition.
Before this change, the ORM supported both styles in
__callStatic(), but internal behavior and tests still depended on the snake_case API. That made it harder to treat the camelCase variants as the real public contract and left one core helper coupled to the legacy naming pattern.The implementation now routes dynamic static methods through a single parser and dispatcher that prefers camelCase names like
findByName,findOneByName,firstByName,lastByName, andcountByName. Legacy snake_case calls still resolve, but they emitE_USER_DEPRECATEDnotices that point callers to the camelCase replacement. The internalfind()helper was also refactored to stop constructingfind_by_<field>dynamically, so the library itself no longer depends on the deprecated method family.The tests and fixture annotations were updated to reflect that shift. CamelCase methods are now the primary contract in the test fixture, the main dynamic finder coverage exercises the camelCase entry points, and the compatibility tests verify that snake_case still works while producing the expected deprecation messages. A regression test was also added to confirm that camelCase lookups still resolve snake_case database columns such as
updated_at.Validation
vendor/bin/phpunit -c phpunit.xml.distvendor/bin/phpstan analyse -c phpstan.neon