Skip to content

Commit 345e1c3

Browse files
authored
refactor: enable code quality level 34 for rector (codeigniter4#9311)
* refactor: enable code quality level 34 for rector * refactor: run cs fix * refactor: fix phpstan and regenerate baseline * refactor: cs fix * refactor: Cors: before never returns string * refactor: return EXIT_ERROR on check verify command * refactor: returns null on DebugToolbar and HoneyPot
1 parent cd8ba91 commit 345e1c3

29 files changed

+90
-67
lines changed

rector.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
use Rector\CodeQuality\Rector\FuncCall\CompactToVariablesRector;
2020
use Rector\CodeQuality\Rector\FunctionLike\SimplifyUselessVariableRector;
2121
use Rector\CodeQuality\Rector\Identical\FlipTypeControlToUseExclusiveTypeRector;
22-
use Rector\CodeQuality\Rector\If_\ShortenElseIfRector;
2322
use Rector\CodeQuality\Rector\Ternary\TernaryEmptyArrayArrayDimFetchToCoalesceRector;
2423
use Rector\CodingStyle\Rector\ClassMethod\FuncGetArgsToVariadicParamRector;
2524
use Rector\CodingStyle\Rector\ClassMethod\MakeInheritedMethodVisibilitySameAsParentRector;
@@ -186,7 +185,6 @@
186185
ChangeIfElseValueAssignToEarlyReturnRector::class,
187186
InlineIfToExplicitIfRector::class,
188187
PreparedValueToEarlyReturnRector::class,
189-
ShortenElseIfRector::class,
190188
UnusedForeachValueToArrayKeysRector::class,
191189
ChangeArrayPushToArrayAssignRector::class,
192190
RemoveErrorSuppressInTryCatchStmtsRector::class,
@@ -210,4 +208,4 @@
210208
// keep '\\' prefix string on string '\Foo\Bar'
211209
StringClassNameToClassConstantRector::SHOULD_KEEP_PRE_SLASH => true,
212210
])
213-
->withCodeQualityLevel(31);
211+
->withCodeQualityLevel(34);

system/CLI/Commands.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,12 @@ public function __construct($logger = null)
5252
/**
5353
* Runs a command given
5454
*
55-
* @return int|void Exit code
55+
* @return int Exit code
5656
*/
5757
public function run(string $command, array $params)
5858
{
5959
if (! $this->verifyCommand($command, $this->commands)) {
60-
return;
60+
return EXIT_ERROR;
6161
}
6262

6363
// The file would have already been loaded during the

system/CodeIgniter.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ private function configureKint(): void
318318
*
319319
* @param bool $returnResponse Used for testing purposes only.
320320
*
321-
* @return ResponseInterface|void
321+
* @return ResponseInterface|null
322322
*/
323323
public function run(?RouteCollectionInterface $routes = null, bool $returnResponse = false)
324324
{
@@ -379,6 +379,8 @@ public function run(?RouteCollectionInterface $routes = null, bool $returnRespon
379379
}
380380

381381
$this->sendResponse();
382+
383+
return null;
382384
}
383385

384386
/**
@@ -863,7 +865,7 @@ protected function determinePath()
863865
* controller method and make the script go. If it's not able to, will
864866
* show the appropriate Page Not Found error.
865867
*
866-
* @return ResponseInterface|string|void
868+
* @return ResponseInterface|string|null
867869
*/
868870
protected function startController()
869871
{
@@ -889,6 +891,8 @@ protected function startController()
889891
) {
890892
throw PageNotFoundException::forControllerNotFound($this->controller, $this->method);
891893
}
894+
895+
return null;
892896
}
893897

894898
/**

system/Commands/Database/MigrateRollback.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public function run(array $params)
7474
$force = array_key_exists('f', $params) || CLI::getOption('f');
7575

7676
if (! $force && CLI::prompt(lang('Migrations.rollBackConfirm'), ['y', 'n']) === 'n') {
77-
return;
77+
return null;
7878
}
7979
// @codeCoverageIgnoreEnd
8080
}
@@ -115,5 +115,7 @@ public function run(array $params)
115115
$this->showError($e);
116116
// @codeCoverageIgnoreEnd
117117
}
118+
119+
return null;
118120
}
119121
}

system/Database/BaseBuilder.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3019,7 +3019,7 @@ protected function _delete(string $table): string
30193019
*
30203020
* @param array|string $table The table to inspect
30213021
*
3022-
* @return string|void
3022+
* @return string|null
30233023
*/
30243024
protected function trackAliases($table)
30253025
{
@@ -3028,7 +3028,7 @@ protected function trackAliases($table)
30283028
$this->trackAliases($t);
30293029
}
30303030

3031-
return;
3031+
return null;
30323032
}
30333033

30343034
// Does the string contain a comma? If so, we need to separate
@@ -3048,6 +3048,8 @@ protected function trackAliases($table)
30483048
// Store the alias, if it doesn't already exist
30493049
$this->db->addTableAlias($alias);
30503050
}
3051+
3052+
return null;
30513053
}
30523054

30533055
/**

system/Filters/CSRF.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,14 @@ class CSRF implements FilterInterface
3535
*
3636
* @param list<string>|null $arguments
3737
*
38-
* @return RedirectResponse|void
38+
* @return RedirectResponse|null
3939
*
4040
* @throws SecurityException
4141
*/
4242
public function before(RequestInterface $request, $arguments = null)
4343
{
4444
if (! $request instanceof IncomingRequest) {
45-
return;
45+
return null;
4646
}
4747

4848
/** @var Security $security */
@@ -57,16 +57,17 @@ public function before(RequestInterface $request, $arguments = null)
5757

5858
throw $e;
5959
}
60+
61+
return null;
6062
}
6163

6264
/**
6365
* We don't have anything to do here.
6466
*
6567
* @param list<string>|null $arguments
66-
*
67-
* @return void
6868
*/
6969
public function after(RequestInterface $request, ResponseInterface $response, $arguments = null)
7070
{
71+
return null;
7172
}
7273
}

system/Filters/Cors.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,18 +48,18 @@ public function __construct(array $config = [])
4848
/**
4949
* @param list<string>|null $arguments
5050
*
51-
* @return ResponseInterface|string|void
51+
* @return ResponseInterface|null
5252
*/
5353
public function before(RequestInterface $request, $arguments = null)
5454
{
5555
if (! $request instanceof IncomingRequest) {
56-
return;
56+
return null;
5757
}
5858

5959
$this->createCorsService($arguments);
6060

6161
if (! $this->cors->isPreflightRequest($request)) {
62-
return;
62+
return null;
6363
}
6464

6565
/** @var ResponseInterface $response */
@@ -88,12 +88,12 @@ private function createCorsService(?array $arguments): void
8888
/**
8989
* @param list<string>|null $arguments
9090
*
91-
* @return ResponseInterface|void
91+
* @return ResponseInterface|null
9292
*/
9393
public function after(RequestInterface $request, ResponseInterface $response, $arguments = null)
9494
{
9595
if (! $request instanceof IncomingRequest) {
96-
return;
96+
return null;
9797
}
9898

9999
$this->createCorsService($arguments);

system/Filters/DebugToolbar.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ class DebugToolbar implements FilterInterface
3030
*/
3131
public function before(RequestInterface $request, $arguments = null)
3232
{
33+
return null;
3334
}
3435

3536
/**
@@ -41,5 +42,7 @@ public function before(RequestInterface $request, $arguments = null)
4142
public function after(RequestInterface $request, ResponseInterface $response, $arguments = null)
4243
{
4344
service('toolbar')->prepare($request, $response);
45+
46+
return null;
4447
}
4548
}

system/Filters/FilterInterface.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ interface FilterInterface
3333
*
3434
* @param list<string>|null $arguments
3535
*
36-
* @return RequestInterface|ResponseInterface|string|void
36+
* @return RequestInterface|ResponseInterface|string|null
3737
*/
3838
public function before(RequestInterface $request, $arguments = null);
3939

@@ -45,7 +45,7 @@ public function before(RequestInterface $request, $arguments = null);
4545
*
4646
* @param list<string>|null $arguments
4747
*
48-
* @return ResponseInterface|void
48+
* @return ResponseInterface|null
4949
*/
5050
public function after(RequestInterface $request, ResponseInterface $response, $arguments = null);
5151
}

system/Filters/ForceHTTPS.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,14 @@ class ForceHTTPS implements FilterInterface
3232
*
3333
* @param array|null $arguments
3434
*
35-
* @return ResponseInterface|void
35+
* @return ResponseInterface|null
3636
*/
3737
public function before(RequestInterface $request, $arguments = null)
3838
{
3939
$config = config(App::class);
4040

4141
if ($config->forceGlobalSecureRequests !== true) {
42-
return;
42+
return null;
4343
}
4444

4545
$response = service('response');
@@ -49,16 +49,17 @@ public function before(RequestInterface $request, $arguments = null)
4949
} catch (RedirectException $e) {
5050
return $e->getResponse();
5151
}
52+
53+
return null;
5254
}
5355

5456
/**
5557
* We don't have anything to do here.
5658
*
5759
* @param array|null $arguments
58-
*
59-
* @return void
6060
*/
6161
public function after(RequestInterface $request, ResponseInterface $response, $arguments = null)
6262
{
63+
return null;
6364
}
6465
}

system/Filters/Honeypot.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,14 @@ class Honeypot implements FilterInterface
3636
public function before(RequestInterface $request, $arguments = null)
3737
{
3838
if (! $request instanceof IncomingRequest) {
39-
return;
39+
return null;
4040
}
4141

4242
if (service('honeypot')->hasContent($request)) {
4343
throw HoneypotException::isBot();
4444
}
45+
46+
return null;
4547
}
4648

4749
/**
@@ -52,5 +54,7 @@ public function before(RequestInterface $request, $arguments = null)
5254
public function after(RequestInterface $request, ResponseInterface $response, $arguments = null)
5355
{
5456
service('honeypot')->attachHoneypot($response);
57+
58+
return null;
5559
}
5660
}

system/Filters/InvalidChars.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,11 @@ class InvalidChars implements FilterInterface
4848
* Check invalid characters.
4949
*
5050
* @param list<string>|null $arguments
51-
*
52-
* @return void
5351
*/
5452
public function before(RequestInterface $request, $arguments = null)
5553
{
5654
if (! $request instanceof IncomingRequest) {
57-
return;
55+
return null;
5856
}
5957

6058
$data = [
@@ -69,17 +67,18 @@ public function before(RequestInterface $request, $arguments = null)
6967
$this->checkEncoding($values);
7068
$this->checkControl($values);
7169
}
70+
71+
return null;
7272
}
7373

7474
/**
7575
* We don't have anything to do here.
7676
*
7777
* @param list<string>|null $arguments
78-
*
79-
* @return void
8078
*/
8179
public function after(RequestInterface $request, ResponseInterface $response, $arguments = null)
8280
{
81+
return null;
8382
}
8483

8584
/**

system/Filters/PageCache.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public function __construct()
3838
*
3939
* @param array|null $arguments
4040
*
41-
* @return ResponseInterface|void
41+
* @return ResponseInterface|null
4242
*/
4343
public function before(RequestInterface $request, $arguments = null)
4444
{
@@ -51,14 +51,14 @@ public function before(RequestInterface $request, $arguments = null)
5151
if ($cachedResponse instanceof ResponseInterface) {
5252
return $cachedResponse;
5353
}
54+
55+
return null;
5456
}
5557

5658
/**
5759
* Cache the page.
5860
*
5961
* @param array|null $arguments
60-
*
61-
* @return void
6262
*/
6363
public function after(RequestInterface $request, ResponseInterface $response, $arguments = null)
6464
{
@@ -72,6 +72,10 @@ public function after(RequestInterface $request, ResponseInterface $response, $a
7272
// so that we can have live speed updates along the way.
7373
// Must be run after filters to preserve the Response headers.
7474
$this->pageCache->make($request, $response);
75+
76+
return $response;
7577
}
78+
79+
return null;
7680
}
7781
}

system/Filters/PerformanceMetrics.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,13 @@ class PerformanceMetrics implements FilterInterface
2828
*/
2929
public function before(RequestInterface $request, $arguments = null)
3030
{
31+
return null;
3132
}
3233

3334
/**
3435
* Replaces the performance metrics.
3536
*
3637
* @param array|null $arguments
37-
*
38-
* @return void
3938
*/
4039
public function after(RequestInterface $request, ResponseInterface $response, $arguments = null)
4140
{
@@ -57,6 +56,10 @@ public function after(RequestInterface $request, ResponseInterface $response, $a
5756
);
5857

5958
$response->setBody($output);
59+
60+
return $response;
6061
}
62+
63+
return null;
6164
}
6265
}

0 commit comments

Comments
 (0)