Skip to content

refactor: change magic model methods to camelCase#19

Merged
davebarnwell merged 3 commits intomainfrom
feature/camel-case-magic-methods
Mar 7, 2026
Merged

refactor: change magic model methods to camelCase#19
davebarnwell merged 3 commits intomainfrom
feature/camel-case-magic-methods

Conversation

@davebarnwell
Copy link
Owner

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, and countByName. Legacy snake_case calls still resolve, but they emit E_USER_DEPRECATED notices that point callers to the camelCase replacement. The internal find() helper was also refactored to stop constructing find_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.dist
  • vendor/bin/phpstan analyse -c phpstan.neon

@davebarnwell davebarnwell marked this pull request as ready for review March 7, 2026 22:17
Copilot AI review requested due to automatic review settings March 7, 2026 22:17
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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, emitting E_USER_DEPRECATED for snake_case variants.
  • Updated internal Model::find() to avoid constructing find_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.

@davebarnwell davebarnwell merged commit 6ccece4 into main Mar 7, 2026
5 checks passed
@davebarnwell davebarnwell deleted the feature/camel-case-magic-methods branch March 7, 2026 22:24
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.

2 participants