Skip to content

Commit

Permalink
refactor: enable code quality level 34 for rector (#9311)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
samsonasik authored Dec 21, 2024
1 parent cd8ba91 commit 345e1c3
Show file tree
Hide file tree
Showing 29 changed files with 90 additions and 67 deletions.
4 changes: 1 addition & 3 deletions rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
use Rector\CodeQuality\Rector\FuncCall\CompactToVariablesRector;
use Rector\CodeQuality\Rector\FunctionLike\SimplifyUselessVariableRector;
use Rector\CodeQuality\Rector\Identical\FlipTypeControlToUseExclusiveTypeRector;
use Rector\CodeQuality\Rector\If_\ShortenElseIfRector;
use Rector\CodeQuality\Rector\Ternary\TernaryEmptyArrayArrayDimFetchToCoalesceRector;
use Rector\CodingStyle\Rector\ClassMethod\FuncGetArgsToVariadicParamRector;
use Rector\CodingStyle\Rector\ClassMethod\MakeInheritedMethodVisibilitySameAsParentRector;
Expand Down Expand Up @@ -186,7 +185,6 @@
ChangeIfElseValueAssignToEarlyReturnRector::class,
InlineIfToExplicitIfRector::class,
PreparedValueToEarlyReturnRector::class,
ShortenElseIfRector::class,
UnusedForeachValueToArrayKeysRector::class,
ChangeArrayPushToArrayAssignRector::class,
RemoveErrorSuppressInTryCatchStmtsRector::class,
Expand All @@ -210,4 +208,4 @@
// keep '\\' prefix string on string '\Foo\Bar'
StringClassNameToClassConstantRector::SHOULD_KEEP_PRE_SLASH => true,
])
->withCodeQualityLevel(31);
->withCodeQualityLevel(34);
4 changes: 2 additions & 2 deletions system/CLI/Commands.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,12 @@ public function __construct($logger = null)
/**
* Runs a command given
*
* @return int|void Exit code
* @return int Exit code
*/
public function run(string $command, array $params)
{
if (! $this->verifyCommand($command, $this->commands)) {
return;
return EXIT_ERROR;
}

// The file would have already been loaded during the
Expand Down
8 changes: 6 additions & 2 deletions system/CodeIgniter.php
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ private function configureKint(): void
*
* @param bool $returnResponse Used for testing purposes only.
*
* @return ResponseInterface|void
* @return ResponseInterface|null
*/
public function run(?RouteCollectionInterface $routes = null, bool $returnResponse = false)
{
Expand Down Expand Up @@ -379,6 +379,8 @@ public function run(?RouteCollectionInterface $routes = null, bool $returnRespon
}

$this->sendResponse();

return null;
}

/**
Expand Down Expand Up @@ -863,7 +865,7 @@ protected function determinePath()
* controller method and make the script go. If it's not able to, will
* show the appropriate Page Not Found error.
*
* @return ResponseInterface|string|void
* @return ResponseInterface|string|null
*/
protected function startController()
{
Expand All @@ -889,6 +891,8 @@ protected function startController()
) {
throw PageNotFoundException::forControllerNotFound($this->controller, $this->method);
}

return null;
}

/**
Expand Down
4 changes: 3 additions & 1 deletion system/Commands/Database/MigrateRollback.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public function run(array $params)
$force = array_key_exists('f', $params) || CLI::getOption('f');

if (! $force && CLI::prompt(lang('Migrations.rollBackConfirm'), ['y', 'n']) === 'n') {
return;
return null;
}
// @codeCoverageIgnoreEnd
}
Expand Down Expand Up @@ -115,5 +115,7 @@ public function run(array $params)
$this->showError($e);
// @codeCoverageIgnoreEnd
}

return null;
}
}
6 changes: 4 additions & 2 deletions system/Database/BaseBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -3019,7 +3019,7 @@ protected function _delete(string $table): string
*
* @param array|string $table The table to inspect
*
* @return string|void
* @return string|null
*/
protected function trackAliases($table)
{
Expand All @@ -3028,7 +3028,7 @@ protected function trackAliases($table)
$this->trackAliases($t);
}

return;
return null;
}

// Does the string contain a comma? If so, we need to separate
Expand All @@ -3048,6 +3048,8 @@ protected function trackAliases($table)
// Store the alias, if it doesn't already exist
$this->db->addTableAlias($alias);
}

return null;
}

/**
Expand Down
9 changes: 5 additions & 4 deletions system/Filters/CSRF.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@ class CSRF implements FilterInterface
*
* @param list<string>|null $arguments
*
* @return RedirectResponse|void
* @return RedirectResponse|null
*
* @throws SecurityException
*/
public function before(RequestInterface $request, $arguments = null)
{
if (! $request instanceof IncomingRequest) {
return;
return null;
}

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

throw $e;
}

return null;
}

/**
* We don't have anything to do here.
*
* @param list<string>|null $arguments
*
* @return void
*/
public function after(RequestInterface $request, ResponseInterface $response, $arguments = null)
{
return null;
}
}
10 changes: 5 additions & 5 deletions system/Filters/Cors.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,18 @@ public function __construct(array $config = [])
/**
* @param list<string>|null $arguments
*
* @return ResponseInterface|string|void
* @return ResponseInterface|null
*/
public function before(RequestInterface $request, $arguments = null)
{
if (! $request instanceof IncomingRequest) {
return;
return null;
}

$this->createCorsService($arguments);

if (! $this->cors->isPreflightRequest($request)) {
return;
return null;
}

/** @var ResponseInterface $response */
Expand Down Expand Up @@ -88,12 +88,12 @@ private function createCorsService(?array $arguments): void
/**
* @param list<string>|null $arguments
*
* @return ResponseInterface|void
* @return ResponseInterface|null
*/
public function after(RequestInterface $request, ResponseInterface $response, $arguments = null)
{
if (! $request instanceof IncomingRequest) {
return;
return null;
}

$this->createCorsService($arguments);
Expand Down
3 changes: 3 additions & 0 deletions system/Filters/DebugToolbar.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class DebugToolbar implements FilterInterface
*/
public function before(RequestInterface $request, $arguments = null)
{
return null;
}

/**
Expand All @@ -41,5 +42,7 @@ public function before(RequestInterface $request, $arguments = null)
public function after(RequestInterface $request, ResponseInterface $response, $arguments = null)
{
service('toolbar')->prepare($request, $response);

return null;
}
}
4 changes: 2 additions & 2 deletions system/Filters/FilterInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ interface FilterInterface
*
* @param list<string>|null $arguments
*
* @return RequestInterface|ResponseInterface|string|void
* @return RequestInterface|ResponseInterface|string|null
*/
public function before(RequestInterface $request, $arguments = null);

Expand All @@ -45,7 +45,7 @@ public function before(RequestInterface $request, $arguments = null);
*
* @param list<string>|null $arguments
*
* @return ResponseInterface|void
* @return ResponseInterface|null
*/
public function after(RequestInterface $request, ResponseInterface $response, $arguments = null);
}
9 changes: 5 additions & 4 deletions system/Filters/ForceHTTPS.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@ class ForceHTTPS implements FilterInterface
*
* @param array|null $arguments
*
* @return ResponseInterface|void
* @return ResponseInterface|null
*/
public function before(RequestInterface $request, $arguments = null)
{
$config = config(App::class);

if ($config->forceGlobalSecureRequests !== true) {
return;
return null;
}

$response = service('response');
Expand All @@ -49,16 +49,17 @@ public function before(RequestInterface $request, $arguments = null)
} catch (RedirectException $e) {
return $e->getResponse();
}

return null;
}

/**
* We don't have anything to do here.
*
* @param array|null $arguments
*
* @return void
*/
public function after(RequestInterface $request, ResponseInterface $response, $arguments = null)
{
return null;
}
}
6 changes: 5 additions & 1 deletion system/Filters/Honeypot.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,14 @@ class Honeypot implements FilterInterface
public function before(RequestInterface $request, $arguments = null)
{
if (! $request instanceof IncomingRequest) {
return;
return null;
}

if (service('honeypot')->hasContent($request)) {
throw HoneypotException::isBot();
}

return null;
}

/**
Expand All @@ -52,5 +54,7 @@ public function before(RequestInterface $request, $arguments = null)
public function after(RequestInterface $request, ResponseInterface $response, $arguments = null)
{
service('honeypot')->attachHoneypot($response);

return null;
}
}
9 changes: 4 additions & 5 deletions system/Filters/InvalidChars.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,11 @@ class InvalidChars implements FilterInterface
* Check invalid characters.
*
* @param list<string>|null $arguments
*
* @return void
*/
public function before(RequestInterface $request, $arguments = null)
{
if (! $request instanceof IncomingRequest) {
return;
return null;
}

$data = [
Expand All @@ -69,17 +67,18 @@ public function before(RequestInterface $request, $arguments = null)
$this->checkEncoding($values);
$this->checkControl($values);
}

return null;
}

/**
* We don't have anything to do here.
*
* @param list<string>|null $arguments
*
* @return void
*/
public function after(RequestInterface $request, ResponseInterface $response, $arguments = null)
{
return null;
}

/**
Expand Down
10 changes: 7 additions & 3 deletions system/Filters/PageCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function __construct()
*
* @param array|null $arguments
*
* @return ResponseInterface|void
* @return ResponseInterface|null
*/
public function before(RequestInterface $request, $arguments = null)
{
Expand All @@ -51,14 +51,14 @@ public function before(RequestInterface $request, $arguments = null)
if ($cachedResponse instanceof ResponseInterface) {
return $cachedResponse;
}

return null;
}

/**
* Cache the page.
*
* @param array|null $arguments
*
* @return void
*/
public function after(RequestInterface $request, ResponseInterface $response, $arguments = null)
{
Expand All @@ -72,6 +72,10 @@ public function after(RequestInterface $request, ResponseInterface $response, $a
// so that we can have live speed updates along the way.
// Must be run after filters to preserve the Response headers.
$this->pageCache->make($request, $response);

return $response;
}

return null;
}
}
7 changes: 5 additions & 2 deletions system/Filters/PerformanceMetrics.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,13 @@ class PerformanceMetrics implements FilterInterface
*/
public function before(RequestInterface $request, $arguments = null)
{
return null;
}

/**
* Replaces the performance metrics.
*
* @param array|null $arguments
*
* @return void
*/
public function after(RequestInterface $request, ResponseInterface $response, $arguments = null)
{
Expand All @@ -57,6 +56,10 @@ public function after(RequestInterface $request, ResponseInterface $response, $a
);

$response->setBody($output);

return $response;
}

return null;
}
}
Loading

0 comments on commit 345e1c3

Please sign in to comment.