Skip to content

Add cakephp54 rector ruleset#408

Merged
dereuromark merged 1 commit into
5.xfrom
feature/cakephp54-rector
Jul 22, 2026
Merged

Add cakephp54 rector ruleset#408
dereuromark merged 1 commit into
5.xfrom
feature/cakephp54-rector

Conversation

@dereuromark

Copy link
Copy Markdown
Member

The 5.4 migration guide already tells users to run

bin/cake upgrade rector --rules cakephp54 <path/to/app/src>

but there was no such ruleset, so the command failed. This adds it.

What is automated

Two of the 5.4 changes are mechanically automatable:

Console helper namespace move. Cake\Command\Helper\{Banner,Progress,Table,Tree}Helper are deprecated in favor of Cake\Console\Helper\*. The core keeps class_alias shims, so a plain RenameClassRector mapping is enough.

SelectQuery::disableHydration() -> Table::unhydratedFind(). New DisableHydrationToUnhydratedFindRector collapses the chain:

// before
$articles->find('all')->disableHydration();
$articles->find()->where(['id' => 1])->contain(['Users'])->disableHydration();

// after
$articles->unhydratedFind('all');
$articles->unhydratedFind()->where(['id' => 1])->contain(['Users']);

It walks down the fluent chain to the originating find() call, so intermediate calls are preserved. It deliberately skips:

  • receivers that are not a Cake\ORM\Table (associations have no unhydratedFind() counterpart)
  • detached queries, i.e. $query->disableHydration() where the find() call is not part of the same chain

Those cases still need a manual look, since the replacement returns a different class (UnhydratedSelectQuery).

Not automated (deliberately)

  • EventAwareApplicationInterface::pluginEvents() is deprecated but still declared on the interface in 5.4, so removing the implementation would break the contract until 6.0. This belongs in the cakephp60 set.
  • Commands are now attached to the event manager by default, so existing manual attach calls should be dropped. Detecting those reliably is too pattern-dependent for a safe codemod.
  • Mailer::$name is deprecated as unused; removing a property an app might still read is not safe to do blind.
  • The HasMany / BelongsToMany default strategy change (select -> subquery) could be pinned back with an opt-in BC ruleset that injects 'strategy' => 'select'. Happy to add that as a follow-up if wanted, but it is opinionated enough that it should not be in the default set.
  • Everything else in the guide is runtime behavior (BaseCommand::initialize() ordering, subcommand token rejection, Number::parseFloat() returning null, deferred afterSaveCommit/afterDeleteCommit, cross-table entity assertions, the FormHelper hidden attribute) with no PHP-level rewrite.

Notes

  • RectorCommandTest::testApply54 plus original/upgraded app fixtures cover the set end to end; the rule itself has focused fixtures including two skip cases.
  • The upgraded fixture keeps the now-unused import and emits an FQCN in the property type. That is existing RenameClassRector behavior in this repo, matching the cakephp53 fixture.
  • FileRenameCommandTest::testTemplates errors locally on 5.x as well, unrelated to this change.

The 5.4 migration guide already tells users to run

    bin/cake upgrade rector --rules cakephp54 <path>

but no such ruleset existed, so the command failed.

Covers the two mechanically automatable 5.4 changes:

- Console helpers moved from the Cake\Command\Helper namespace to
  Cake\Console\Helper. The core keeps class_alias shims, so this is a
  plain class rename.
- SelectQuery::disableHydration() is deprecated in favor of the new
  Table::unhydratedFind(), which returns an UnhydratedSelectQuery whose
  static type matches the array result shape. The new
  DisableHydrationToUnhydratedFindRector collapses a
  find()->...->disableHydration() chain into unhydratedFind()->...,
  and skips receivers that are not a Table as well as detached queries
  where the originating find() call is not part of the chain.
@dereuromark
dereuromark merged commit 738c8ec into 5.x Jul 22, 2026
3 checks passed
@dereuromark
dereuromark deleted the feature/cakephp54-rector branch July 22, 2026 18:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants