Skip to content

Commit 2fdfb2a

Browse files
committed
Add rector rules for cakephp/authentication 4.x upgrade
Adds rules to automate the 3.x to 4.x migration for the authentication plugin: - Rename CakeRouterUrlChecker to DefaultUrlChecker - Rename DefaultUrlChecker (framework-agnostic) to GenericUrlChecker - Rename Plugin to AuthenticationPlugin - Remove loadIdentifier() method calls See: cakephp/authentication#748
1 parent 19e65a4 commit 2fdfb2a

File tree

3 files changed

+44
-0
lines changed

3 files changed

+44
-0
lines changed

config/rector/authentication40.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
use Cake\Upgrade\Rector\Set\CakePHPSetList;
5+
use Rector\Config\RectorConfig;
6+
7+
return static function (RectorConfig $rectorConfig): void {
8+
$rectorConfig->sets([CakePHPSetList::AUTHENTICATION_40]);
9+
};
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
use Cake\Upgrade\Rector\Rector\MethodCall\RemoveMethodCallRector;
5+
use Cake\Upgrade\Rector\ValueObject\RemoveMethodCall;
6+
use Rector\Config\RectorConfig;
7+
use Rector\Renaming\Rector\Name\RenameClassRector;
8+
9+
/**
10+
* @see https://github.com/cakephp/authentication/blob/4.x/docs/en/upgrade-3-to-4.rst
11+
*/
12+
return static function (RectorConfig $rectorConfig): void {
13+
// URL checker class renames
14+
// Note: Order matters - GenericUrlChecker rename must come first to avoid
15+
// CakeRouterUrlChecker -> DefaultUrlChecker -> GenericUrlChecker chain
16+
$rectorConfig->ruleWithConfiguration(RenameClassRector::class, [
17+
// Old framework-agnostic DefaultUrlChecker renamed to GenericUrlChecker
18+
'Authentication\UrlChecker\DefaultUrlChecker' => 'Authentication\UrlChecker\GenericUrlChecker',
19+
// CakeRouterUrlChecker renamed to DefaultUrlChecker
20+
'Authentication\UrlChecker\CakeRouterUrlChecker' => 'Authentication\UrlChecker\DefaultUrlChecker',
21+
// Plugin class renamed
22+
'Authentication\Plugin' => 'Authentication\AuthenticationPlugin',
23+
]);
24+
25+
// Remove loadIdentifier() method calls from AuthenticationService
26+
$rectorConfig->ruleWithConfiguration(RemoveMethodCallRector::class, [
27+
new RemoveMethodCall('Authentication\AuthenticationService', 'loadIdentifier'),
28+
new RemoveMethodCall('Authentication\AuthenticationServiceInterface', 'loadIdentifier'),
29+
]);
30+
};

src/Rector/Set/CakePHPSetList.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,4 +104,9 @@ final class CakePHPSetList
104104
* @var string
105105
*/
106106
public const CAKEPHP_FLUENT_OPTIONS = __DIR__ . '/../../../config/rector/sets/cakephp-fluent-options.php';
107+
108+
/**
109+
* @var string
110+
*/
111+
public const AUTHENTICATION_40 = __DIR__ . '/../../../config/rector/sets/authentication40.php';
107112
}

0 commit comments

Comments
 (0)