Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions config/rector/authentication40.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php
declare(strict_types=1);

use Cake\Upgrade\Rector\Set\CakePHPSetList;
use Rector\Config\RectorConfig;

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->sets([CakePHPSetList::AUTHENTICATION_40]);
};
30 changes: 30 additions & 0 deletions config/rector/sets/authentication40.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php
declare(strict_types=1);

use Cake\Upgrade\Rector\Rector\MethodCall\RemoveMethodCallRector;
use Cake\Upgrade\Rector\ValueObject\RemoveMethodCall;
use Rector\Config\RectorConfig;
use Rector\Renaming\Rector\Name\RenameClassRector;

/**
* @see https://github.com/cakephp/authentication/blob/4.x/docs/en/upgrade-3-to-4.rst
*/
return static function (RectorConfig $rectorConfig): void {
// URL checker class renames
// Note: Order matters - StringUrlChecker rename must come first to avoid
// CakeRouterUrlChecker -> DefaultUrlChecker -> StringUrlChecker chain
$rectorConfig->ruleWithConfiguration(RenameClassRector::class, [
// Old DefaultUrlChecker renamed to StringUrlChecker
'Authentication\UrlChecker\DefaultUrlChecker' => 'Authentication\UrlChecker\StringUrlChecker',
// CakeRouterUrlChecker renamed to DefaultUrlChecker
'Authentication\UrlChecker\CakeRouterUrlChecker' => 'Authentication\UrlChecker\DefaultUrlChecker',
Comment on lines +18 to +20
Copy link
Member

Choose a reason for hiding this comment

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

If you run this more than once will all the UrlChecker references end up as StringUrlChecker?

Copy link
Member Author

@dereuromark dereuromark Dec 15, 2025

Choose a reason for hiding this comment

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

Yeah, that is not really idempotent right now

I dont have any great ideas other than: Marker comment

  // @upgraded-authentication-4.0
  use Authentication\UrlChecker\DefaultUrlChecker;

and then skip it.

This could be a bit difficult with inline usage of FQCN.

Alternative: file-level docblock

  <?php
  /**
   * @rector-upgraded authentication40
   */

once we run it.

Copy link
Member Author

Choose a reason for hiding this comment

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

Or: we just drop the old Default one rename.
And only rename the cake to default one.

No one outside of cake would use the upgrade tool here, and the few cases of people using the "external" over the cake router internal one would be almost irrelevant I assume.

Copy link
Member

Choose a reason for hiding this comment

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

Skipping the rename on the existing default checker could work. I agree that there are likely few references to it in application code.

// Plugin class renamed
'Authentication\Plugin' => 'Authentication\AuthenticationPlugin',
]);

// Remove loadIdentifier() method calls from AuthenticationService
$rectorConfig->ruleWithConfiguration(RemoveMethodCallRector::class, [
new RemoveMethodCall('Authentication\AuthenticationService', 'loadIdentifier'),
new RemoveMethodCall('Authentication\AuthenticationServiceInterface', 'loadIdentifier'),
]);
};
5 changes: 5 additions & 0 deletions src/Rector/Set/CakePHPSetList.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,9 @@ final class CakePHPSetList
* @var string
*/
public const CAKEPHP_FLUENT_OPTIONS = __DIR__ . '/../../../config/rector/sets/cakephp-fluent-options.php';

/**
* @var string
*/
public const AUTHENTICATION_40 = __DIR__ . '/../../../config/rector/sets/authentication40.php';
}