Skip to content

Commit 20554c2

Browse files
authored
Merge pull request #154 from cakephp/rector
add rector
2 parents 28d2978 + fad5fb0 commit 20554c2

22 files changed

+212
-62
lines changed

.github/workflows/ci.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,3 +85,18 @@ jobs:
8585

8686
- name: Run PHPStan
8787
run: vendor/bin/phpstan analyse -c phpstan.neon --error-format=checkstyle | cs2pr
88+
89+
- name: Setup rector cache
90+
uses: actions/cache@v5
91+
with:
92+
path: ${{ runner.temp }}/rector
93+
key: ${{ runner.os }}-rector-${{ hashFiles('rector.php', 'composer.lock') }}
94+
restore-keys: ${{ runner.os }}-rector-
95+
96+
- name: Create rector cache dir
97+
run: mkdir -p ${{ runner.temp }}/rector
98+
99+
- name: Run rector
100+
env:
101+
RECTOR_CACHE_DIR: ${{ runner.temp }}/rector
102+
run: composer rector-setup && composer rector-check

composer.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@
6464
"annotate": "bin/cake annotate all",
6565
"illuminate": "bin/cake illuminate code",
6666
"phpstan": "phpstan analyse",
67-
"phpstan-baseline": "phpstan --generate-baseline"
67+
"phpstan-baseline": "phpstan --generate-baseline",
68+
"rector-setup": "cp composer.json composer.backup && composer require --dev rector/rector:\"~2.3.1\" && mv composer.backup composer.json",
69+
"rector-check": "vendor/bin/rector process --dry-run",
70+
"rector-fix": "vendor/bin/rector process"
6871
}
6972
}

composer.lock

Lines changed: 61 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/app.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@
119119
'default' => [
120120
'className' => FileEngine::class,
121121
'path' => CACHE,
122-
'url' => env('CACHE_DEFAULT_URL', null),
122+
'url' => env('CACHE_DEFAULT_URL'),
123123
],
124124

125125
/*
@@ -134,7 +134,7 @@
134134
'path' => CACHE . 'persistent' . DS,
135135
'serialize' => true,
136136
'duration' => '+1 years',
137-
'url' => env('CACHE_CAKECORE_URL', null),
137+
'url' => env('CACHE_CAKECORE_URL'),
138138
],
139139

140140
/*
@@ -149,7 +149,7 @@
149149
'path' => CACHE . 'models' . DS,
150150
'serialize' => true,
151151
'duration' => '+1 years',
152-
'url' => env('CACHE_CAKEMODEL_URL', null),
152+
'url' => env('CACHE_CAKEMODEL_URL'),
153153
],
154154
],
155155

@@ -250,7 +250,7 @@
250250
//'password' => null,
251251
'client' => null,
252252
'tls' => false,
253-
'url' => env('EMAIL_TRANSPORT_DEFAULT_URL', null),
253+
'url' => env('EMAIL_TRANSPORT_DEFAULT_URL'),
254254
],
255255
],
256256

@@ -364,15 +364,15 @@
364364
'className' => FileLog::class,
365365
'path' => LOGS,
366366
'file' => 'debug',
367-
'url' => env('LOG_DEBUG_URL', null),
367+
'url' => env('LOG_DEBUG_URL'),
368368
'scopes' => null,
369369
'levels' => ['notice', 'info', 'debug'],
370370
],
371371
'error' => [
372372
'className' => FileLog::class,
373373
'path' => LOGS,
374374
'file' => 'error',
375-
'url' => env('LOG_ERROR_URL', null),
375+
'url' => env('LOG_ERROR_URL'),
376376
'scopes' => null,
377377
'levels' => ['warning', 'error', 'critical', 'alert', 'emergency'],
378378
],
@@ -381,7 +381,7 @@
381381
'className' => FileLog::class,
382382
'path' => LOGS,
383383
'file' => 'queries',
384-
'url' => env('LOG_QUERIES_URL', null),
384+
'url' => env('LOG_QUERIES_URL'),
385385
'scopes' => ['cake.database.queries'],
386386
],
387387
],
@@ -459,7 +459,7 @@
459459
*/
460460
'DebugKit' => [
461461
'forceEnable' => filter_var(env('DEBUG_KIT_FORCE_ENABLE', false), FILTER_VALIDATE_BOOLEAN),
462-
'safeTld' => env('DEBUG_KIT_SAFE_TLD', null),
462+
'safeTld' => env('DEBUG_KIT_SAFE_TLD'),
463463
'ignoreAuthorization' => env('DEBUG_KIT_IGNORE_AUTHORIZATION', false),
464464
],
465465

config/app_local.example.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
/*
6161
* You can use a DSN string to set the entire configuration
6262
*/
63-
'url' => env('DATABASE_URL', null),
63+
'url' => env('DATABASE_URL'),
6464
],
6565

6666
/*
@@ -91,7 +91,7 @@
9191
'username' => null,
9292
'password' => null,
9393
'client' => null,
94-
'url' => env('EMAIL_TRANSPORT_DEFAULT_URL', null),
94+
'url' => env('EMAIL_TRANSPORT_DEFAULT_URL'),
9595
],
9696
],
9797
];

config/bootstrap.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,12 +194,12 @@
194194
* If you don't use these checks you can safely remove this code
195195
* and the mobiledetect package from composer.json.
196196
*/
197-
ServerRequest::addDetector('mobile', function ($request) {
197+
ServerRequest::addDetector('mobile', function ($request): bool {
198198
$detector = new MobileDetect();
199199

200200
return $detector->isMobile();
201201
});
202-
ServerRequest::addDetector('tablet', function ($request) {
202+
ServerRequest::addDetector('tablet', function ($request): bool {
203203
$detector = new MobileDetect();
204204

205205
return $detector->isTablet();

rector.php

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
use Rector\Caching\ValueObject\Storage\FileCacheStorage;
5+
use Rector\CodeQuality\Rector\Empty_\SimplifyEmptyCheckOnEmptyArrayRector;
6+
use Rector\CodeQuality\Rector\FuncCall\CompactToVariablesRector;
7+
use Rector\CodeQuality\Rector\If_\ExplicitBoolCompareRector;
8+
use Rector\CodingStyle\Rector\Assign\SplitDoubleAssignRector;
9+
use Rector\CodingStyle\Rector\Catch_\CatchExceptionNameMatchingTypeRector;
10+
use Rector\CodingStyle\Rector\ClassMethod\NewlineBeforeNewAssignSetRector;
11+
use Rector\CodingStyle\Rector\Stmt\NewlineAfterStatementRector;
12+
use Rector\Config\RectorConfig;
13+
use Rector\DeadCode\Rector\ClassMethod\RemoveUselessParamTagRector;
14+
use Rector\DeadCode\Rector\ClassMethod\RemoveUselessReturnTagRector;
15+
use Rector\EarlyReturn\Rector\If_\ChangeOrIfContinueToMultiContinueRector;
16+
use Rector\Php55\Rector\String_\StringClassNameToClassConstantRector;
17+
use Rector\Php74\Rector\Closure\ClosureToArrowFunctionRector;
18+
use Rector\Php80\Rector\Class_\ClassPropertyAssignToConstructorPromotionRector;
19+
use Rector\Php80\Rector\Class_\StringableForToStringRector;
20+
use Rector\Set\ValueObject\SetList;
21+
use Rector\Strict\Rector\Empty_\DisallowedEmptyRuleFixerRector;
22+
use Rector\TypeDeclaration\Rector\ClassMethod\ParamTypeByMethodCallTypeRector;
23+
use Rector\TypeDeclaration\Rector\ClassMethod\ReturnTypeFromStrictFluentReturnRector;
24+
use Rector\TypeDeclaration\Rector\ClassMethod\ReturnTypeFromStrictTypedCallRector;
25+
use Rector\TypeDeclaration\Rector\Function_\AddFunctionVoidReturnTypeWhereNoReturnRector;
26+
27+
$cacheDir = getenv('RECTOR_CACHE_DIR') ?: sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'rector';
28+
29+
return RectorConfig::configure()
30+
->withPaths([
31+
__DIR__ . '/config',
32+
__DIR__ . '/src',
33+
__DIR__ . '/tests',
34+
])
35+
36+
->withCache(
37+
cacheClass: FileCacheStorage::class,
38+
cacheDirectory: $cacheDir,
39+
)
40+
41+
->withPhpSets()
42+
->withAttributesSets()
43+
44+
->withSets([
45+
SetList::CODE_QUALITY,
46+
SetList::CODING_STYLE,
47+
SetList::DEAD_CODE,
48+
SetList::EARLY_RETURN,
49+
SetList::INSTANCEOF,
50+
SetList::TYPE_DECLARATION,
51+
])
52+
53+
->withSkip([
54+
ClassPropertyAssignToConstructorPromotionRector::class,
55+
CatchExceptionNameMatchingTypeRector::class,
56+
ClosureToArrowFunctionRector::class,
57+
RemoveUselessReturnTagRector::class,
58+
ReturnTypeFromStrictFluentReturnRector::class,
59+
NewlineAfterStatementRector::class,
60+
StringClassNameToClassConstantRector::class,
61+
ReturnTypeFromStrictTypedCallRector::class,
62+
ParamTypeByMethodCallTypeRector::class,
63+
CompactToVariablesRector::class,
64+
SplitDoubleAssignRector::class,
65+
ChangeOrIfContinueToMultiContinueRector::class,
66+
ExplicitBoolCompareRector::class,
67+
NewlineBeforeNewAssignSetRector::class,
68+
DisallowedEmptyRuleFixerRector::class,
69+
RemoveUselessParamTagRector::class,
70+
]);

src/Application.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,6 @@ public function services(ContainerInterface $container): void
152152
}
153153

154154
/**
155-
* @param \Psr\Http\Message\ServerRequestInterface $request
156155
* @return \Authentication\AuthenticationServiceInterface
157156
*/
158157
public function getAuthenticationService(ServerRequestInterface $request): AuthenticationServiceInterface

src/Command/CleanCommand.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ class CleanCommand extends Command
1414
{
1515
/**
1616
* The name of this command.
17-
*
18-
* @var string
1917
*/
2018
protected string $name = 'clean';
2119

@@ -44,9 +42,9 @@ public static function getDescription(): string
4442
*
4543
* @param \Cake\Console\Arguments $args The command arguments.
4644
* @param \Cake\Console\ConsoleIo $io The console io
47-
* @return int|null|void The exit code or null for success
45+
* @return void The exit code or null for success
4846
*/
49-
public function execute(Arguments $args, ConsoleIo $io)
47+
public function execute(Arguments $args, ConsoleIo $io): void
5048
{
5149
$confirmation = $io->ask(
5250
'Are you sure you want to clean all packages data and related tags? This action cannot be undone. (yes/no)',

src/Command/DevserverCommand.php

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ class DevserverCommand extends Command
1717
{
1818
/**
1919
* The name of this command.
20-
*
21-
* @var string
2220
*/
2321
protected string $name = 'devserver';
2422

@@ -49,7 +47,7 @@ public static function getDescription(): string
4947
* @param \Cake\Console\ConsoleOptionParser $parser The parser to be defined
5048
* @return \Cake\Console\ConsoleOptionParser The built parser.
5149
*/
52-
public function buildOptionParser(ConsoleOptionParser $parser): ConsoleOptionParser
50+
protected function buildOptionParser(ConsoleOptionParser $parser): ConsoleOptionParser
5351
{
5452
return parent::buildOptionParser($parser)
5553
->setDescription(static::getDescription());
@@ -102,10 +100,10 @@ public function execute(Arguments $args, ConsoleIo $io): ?int
102100
if (!$process->isRunning()) {
103101
$poll = false;
104102
$exitCode = $process->getExitCode();
105-
$io->error("$name has died with code $exitCode.");
103+
$io->error(sprintf('%s has died with code %s.', $name, $exitCode));
106104
$errorOutput = trim($process->getErrorOutput());
107105
if ($errorOutput !== '') {
108-
$io->error("$name | $errorOutput");
106+
$io->error(sprintf('%s | %s', $name, $errorOutput));
109107
}
110108
break;
111109
}
@@ -115,7 +113,7 @@ public function execute(Arguments $args, ConsoleIo $io): ?int
115113
if (!empty($output)) {
116114
foreach (explode("\n", trim($output)) as $line) {
117115
if ($line !== '') {
118-
$io->info("$name | $line");
116+
$io->info(sprintf('%s | %s', $name, $line));
119117
}
120118
}
121119
}
@@ -124,7 +122,7 @@ public function execute(Arguments $args, ConsoleIo $io): ?int
124122
if (!empty($error)) {
125123
foreach (explode("\n", trim($error)) as $line) {
126124
if ($line !== '') {
127-
$io->comment("$name | $line");
125+
$io->comment(sprintf('%s | %s', $name, $line));
128126
}
129127
}
130128
}
@@ -135,7 +133,6 @@ public function execute(Arguments $args, ConsoleIo $io): ?int
135133

136134
$io->verbose('Start shutdown');
137135
foreach ($servers as $server) {
138-
/** @var \Symfony\Component\Process\Process $process */
139136
$process = $server['process'];
140137
if ($process->isRunning()) {
141138
$process->stop(1); // graceful timeout of 1 second

0 commit comments

Comments
 (0)