From 3e672fadc6d5277d085ab17cb850db54ef008859 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Tue, 5 Nov 2024 05:03:14 +0700 Subject: [PATCH] refactor: enable FlipTypeControlToUseExclusiveTypeRector --- rector.php | 2 ++ system/CodeIgniter.php | 2 +- system/Common.php | 2 +- system/Database/BaseConnection.php | 2 +- system/Database/Migration.php | 2 +- system/Database/Seeder.php | 2 +- system/HTTP/DownloadResponse.php | 4 ++-- system/HTTP/Exceptions/RedirectException.php | 2 +- system/HTTP/Negotiate.php | 2 +- system/HTTP/SiteURI.php | 2 +- system/Log/Handlers/ChromeLoggerHandler.php | 2 +- system/Validation/FileRules.php | 2 +- tests/system/API/ResponseTraitTest.php | 2 +- utils/src/Rector/UnderscoreToCamelCaseVariableNameRector.php | 2 +- 14 files changed, 16 insertions(+), 14 deletions(-) diff --git a/rector.php b/rector.php index 89647759b914..be9e45f1e169 100644 --- a/rector.php +++ b/rector.php @@ -19,6 +19,7 @@ use Rector\CodeQuality\Rector\FuncCall\ChangeArrayPushToArrayAssignRector; use Rector\CodeQuality\Rector\FuncCall\SingleInArrayToCompareRector; use Rector\CodeQuality\Rector\FunctionLike\SimplifyUselessVariableRector; +use Rector\CodeQuality\Rector\Identical\FlipTypeControlToUseExclusiveTypeRector; use Rector\CodeQuality\Rector\Identical\SimplifyBoolIdenticalTrueRector; use Rector\CodeQuality\Rector\If_\CombineIfRector; use Rector\CodeQuality\Rector\If_\ExplicitBoolCompareRector; @@ -213,6 +214,7 @@ TypedPropertyFromAssignsRector::class, ClosureReturnTypeRector::class, SimplifyBoolIdenticalTrueRector::class, + FlipTypeControlToUseExclusiveTypeRector::class, ]) ->withConfiguredRule(StringClassNameToClassConstantRector::class, [ // keep '\\' prefix string on string '\Foo\Bar' diff --git a/system/CodeIgniter.php b/system/CodeIgniter.php index 48fbc9d77e23..359e3ff7d08d 100644 --- a/system/CodeIgniter.php +++ b/system/CodeIgniter.php @@ -819,7 +819,7 @@ protected function tryToRouteIt(?RouteCollectionInterface $routes = null) { $this->benchmark->start('routing'); - if ($routes === null) { + if (! $routes instanceof RouteCollectionInterface) { $routes = service('routes')->loadRoutes(); } diff --git a/system/Common.php b/system/Common.php index dcc9487c588f..94ecc75e9841 100644 --- a/system/Common.php +++ b/system/Common.php @@ -869,7 +869,7 @@ function _solidus(?DocTypes $docTypesConfig = null): string { static $docTypes = null; - if ($docTypesConfig !== null) { + if ($docTypesConfig instanceof DocTypes) { $docTypes = $docTypesConfig; } diff --git a/system/Database/BaseConnection.php b/system/Database/BaseConnection.php index 65bf6fcdbdac..c60c2e72c680 100644 --- a/system/Database/BaseConnection.php +++ b/system/Database/BaseConnection.php @@ -684,7 +684,7 @@ public function query(string $sql, $binds = null, bool $setEscapeFlags = true, s // Let others do something with this query. Events::trigger('DBQuery', $query); - if ($exception !== null) { + if ($exception instanceof DatabaseException) { throw new DatabaseException( $exception->getMessage(), $exception->getCode(), diff --git a/system/Database/Migration.php b/system/Database/Migration.php index 4386b7448e80..ca9e5e0cf266 100644 --- a/system/Database/Migration.php +++ b/system/Database/Migration.php @@ -45,7 +45,7 @@ public function __construct(?Forge $forge = null) { if (isset($this->DBGroup)) { $this->forge = Database::forge($this->DBGroup); - } elseif ($forge !== null) { + } elseif ($forge instanceof Forge) { $this->forge = $forge; } else { $this->forge = Database::forge(config(Database::class)->defaultGroup); diff --git a/system/Database/Seeder.php b/system/Database/Seeder.php index be7cfcdf8a8c..c70a34b45e9f 100644 --- a/system/Database/Seeder.php +++ b/system/Database/Seeder.php @@ -105,7 +105,7 @@ public function __construct(Database $config, ?BaseConnection $db = null) */ public static function faker(): ?Generator { - if (self::$faker === null && class_exists(Factory::class)) { + if (! self::$faker instanceof Generator && class_exists(Factory::class)) { self::$faker = Factory::create(); } diff --git a/system/HTTP/DownloadResponse.php b/system/HTTP/DownloadResponse.php index 56953823693d..13a1e2b2feaa 100644 --- a/system/HTTP/DownloadResponse.php +++ b/system/HTTP/DownloadResponse.php @@ -85,7 +85,7 @@ public function __construct(string $filename, bool $setMime) */ public function setBinary(string $binary) { - if ($this->file !== null) { + if ($this->file instanceof File) { throw DownloadException::forCannotSetBinary(); } @@ -309,7 +309,7 @@ public function sendBody() return $this->sendBodyByBinary(); } - if ($this->file !== null) { + if ($this->file instanceof File) { return $this->sendBodyByFilePath(); } diff --git a/system/HTTP/Exceptions/RedirectException.php b/system/HTTP/Exceptions/RedirectException.php index 5f2dcd05e3b7..3047bf9603eb 100644 --- a/system/HTTP/Exceptions/RedirectException.php +++ b/system/HTTP/Exceptions/RedirectException.php @@ -69,7 +69,7 @@ public function __construct($message = '', int $code = 0, ?Throwable $previous = public function getResponse(): ResponseInterface { - if (null === $this->response) { + if (! $this->response instanceof ResponseInterface) { $this->response = service('response') ->redirect(base_url($this->getMessage()), 'auto', $this->getCode()); } diff --git a/system/HTTP/Negotiate.php b/system/HTTP/Negotiate.php index 4f218347738d..33938c8f0741 100644 --- a/system/HTTP/Negotiate.php +++ b/system/HTTP/Negotiate.php @@ -39,7 +39,7 @@ class Negotiate */ public function __construct(?RequestInterface $request = null) { - if ($request !== null) { + if ($request instanceof RequestInterface) { assert($request instanceof IncomingRequest); $this->request = $request; diff --git a/system/HTTP/SiteURI.php b/system/HTTP/SiteURI.php index ab0cdd19c955..91b14bc05456 100644 --- a/system/HTTP/SiteURI.php +++ b/system/HTTP/SiteURI.php @@ -421,7 +421,7 @@ public function siteUrl($relativePath = '', ?string $scheme = null, ?App $config $relativePath = $this->stringifyRelativePath($relativePath); // Check current host. - $host = $config === null ? $this->getHost() : null; + $host = ! $config instanceof App ? $this->getHost() : null; $config ??= config(App::class); diff --git a/system/Log/Handlers/ChromeLoggerHandler.php b/system/Log/Handlers/ChromeLoggerHandler.php index 8d39d4c06705..192f7f2951b8 100644 --- a/system/Log/Handlers/ChromeLoggerHandler.php +++ b/system/Log/Handlers/ChromeLoggerHandler.php @@ -156,7 +156,7 @@ protected function format($object) */ public function sendLogs(?ResponseInterface &$response = null) { - if ($response === null) { + if (! $response instanceof ResponseInterface) { $response = Services::response(null, true); } diff --git a/system/Validation/FileRules.php b/system/Validation/FileRules.php index dd8c4290e11d..78d0ce521809 100644 --- a/system/Validation/FileRules.php +++ b/system/Validation/FileRules.php @@ -38,7 +38,7 @@ class FileRules */ public function __construct(?RequestInterface $request = null) { - if ($request === null) { + if (! $request instanceof RequestInterface) { $request = service('request'); } diff --git a/tests/system/API/ResponseTraitTest.php b/tests/system/API/ResponseTraitTest.php index 82229b014bd4..25cccfbfca2a 100644 --- a/tests/system/API/ResponseTraitTest.php +++ b/tests/system/API/ResponseTraitTest.php @@ -87,7 +87,7 @@ private function createRequestAndResponse(string $routePath = '', array $userHea $config = $this->createAppConfig(); $this->createCookieConfig(); - if ($this->request === null) { + if (! $this->request instanceof MockIncomingRequest) { $this->request = new MockIncomingRequest( $config, new SiteURI($config, $routePath), diff --git a/utils/src/Rector/UnderscoreToCamelCaseVariableNameRector.php b/utils/src/Rector/UnderscoreToCamelCaseVariableNameRector.php index ec454b0e017f..25d09fadacb6 100644 --- a/utils/src/Rector/UnderscoreToCamelCaseVariableNameRector.php +++ b/utils/src/Rector/UnderscoreToCamelCaseVariableNameRector.php @@ -164,7 +164,7 @@ private function processRenameVariable(Node $node): ?Variable private function updateDocblock(string $variableName, string $camelCaseName, ?FunctionLike $functionLike): void { - if ($functionLike === null) { + if (! $functionLike instanceof FunctionLike) { return; }