Skip to content

6.x new rectors#343

Closed
dereuromark wants to merge 1 commit into6.xfrom
6.x-new-rectors
Closed

6.x new rectors#343
dereuromark wants to merge 1 commit into6.xfrom
6.x-new-rectors

Conversation

@dereuromark
Copy link
Copy Markdown
Member

Implement some more of https://github.com/cakephp/docs/blob/6.x/en/appendices/6-0-migration-guide.rst

Overview

Three new Rector rules have been implemented to automate CakePHP 6.0 migration changes that were previously not covered.


1. RequestQueryParamRector

File: src/Rector/Rector/MethodCall/RequestQueryParamRector.php

Purpose: Replace $request->getParam('?') with $request->getQueryParams()

Migration Guide Reference: Section 2.3 - Query Parameter Access Change

What it does:

  • Detects $request->getParam('?') calls on Cake\Http\ServerRequest instances
  • Replaces them with $request->getQueryParams() (no arguments)
  • Only transforms when the argument is exactly the string '?'

Example:

// Before
$queryParams = $request->getParam('?');

// After
$queryParams = $request->getQueryParams();

2. TextInsertPlaceholderRector

File: src/Rector/Rector/MethodCall/TextInsertPlaceholderRector.php

Purpose: Replace :placeholder with {placeholder} in Text::insert() calls

Migration Guide Reference: Section 2.4 - Text::insert() Placeholder Format Change

What it does:

  • Detects Text::insert() static calls
  • Transforms placeholder format from :name to {name} in template strings
  • Respects backward compatibility: Skips transformation if 'before' or 'after' options are explicitly set
  • Uses regex pattern /:(\w+)/ to match placeholders (word characters only)

Example:

// Before
Text::insert('Hello :name', ['name' => 'World']);
Text::insert('Hello :first :last', ['first' => 'John', 'last' => 'Doe']);

// After
Text::insert('Hello {name}', ['name' => 'World']);
Text::insert('Hello {first} {last}', ['first' => 'John', 'last' => 'Doe']);

// Not transformed (custom options)
Text::insert('Hello :name', ['name' => 'World'], ['before' => ':', 'after' => '']);

3. RenameFormHelperTemplateKeyRector

File: src/Rector/Rector/String_/RenameFormHelperTemplateKeyRector.php

Purpose: Rename 'multicheckboxTitle' to 'multicheckboxLabel' in FormHelper template configurations

Migration Guide Reference: Section 2.6 - FormHelper Template Key Rename

What it does:

  • Detects array items with string key 'multicheckboxTitle'
  • Renames the key to 'multicheckboxLabel'
  • Context-aware: Only transforms when used as an array key (not as a value)

Example:

// Before
$this->Form->setTemplates([
    'multicheckboxTitle' => '<legend>{{text}}</legend>',
    'inputContainer' => '<div class="input">{{content}}</div>',
]);

// After
$this->Form->setTemplates([
    'multicheckboxLabel' => '<legend>{{text}}</legend>',
    'inputContainer' => '<div class="input">{{content}}</div>',
]);

// Not transformed (used as value, not key)
$someVar = 'multicheckboxTitle';

Comment on lines +15 to +19

?>
-----
<?php

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Does this actually work? How do we update the contents of these files? With the current separate file setup we have in some tests one can use UPDATE_TEST_COMPARISON_FILES=1 to regenerate the baseline files.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The test automatically:

  1. Reads all .php.inc files from the Fixture directory (line 21 in the test)
  2. Splits each file on the ----- separator
  3. Applies the Rector rule to the "before" code
  4. Asserts that the result matches the "after" code

so I guess it does

@dereuromark
Copy link
Copy Markdown
Member Author

@LordSimal we should actually backport those to 5.3 right?
Currently its a bit a mess with other rules already, but IMO we should make the rule for the version it deprecated it not the one it requires it.

@dereuromark dereuromark marked this pull request as draft November 10, 2025 15:42
@dereuromark dereuromark deleted the 6.x-new-rectors branch November 10, 2025 16:13
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