From 49d4589b7b529c0c5b6a288357b42367e1f18d75 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Sun, 23 Aug 2026 19:37:30 +0700 Subject: [PATCH 1/2] Bump Rector to 2.6.3, clean up deprecated rules, and re-run it --- composer.json | 2 +- rector.php | 10 ---------- system/CLI/InputOutput.php | 2 +- system/Config/DotEnv.php | 2 +- system/Database/Postgre/Builder.php | 2 +- system/Files/File.php | 2 +- system/HTTP/ResponseTrait.php | 4 ++-- system/HTTP/SiteURI.php | 4 ++-- system/Helpers/url_helper.php | 2 +- system/Honeypot/Honeypot.php | 2 +- system/I18n/TimeTrait.php | 2 +- system/Router/RouteCollection.php | 2 +- system/Test/Mock/MockConnection.php | 2 +- 13 files changed, 14 insertions(+), 24 deletions(-) diff --git a/composer.json b/composer.json index 7fbbd44313bc..046faefcf83a 100644 --- a/composer.json +++ b/composer.json @@ -29,7 +29,7 @@ "phpunit/phpcov": "^9.0.2 || ^10.0", "phpunit/phpunit": "^10.5.16 || ^11.2", "predis/predis": "^3.0", - "rector/rector": "2.6.1", + "rector/rector": "2.6.3", "shipmonk/phpstan-baseline-per-identifier": "^2.0" }, "replace": { diff --git a/rector.php b/rector.php index f1bc1ae27374..4cb10eecfa10 100644 --- a/rector.php +++ b/rector.php @@ -25,10 +25,6 @@ use Rector\DeadCode\Rector\ClassMethod\RemoveUnusedPrivateMethodRector; use Rector\DeadCode\Rector\MethodCall\RemoveNullArgOnNullDefaultParamRector; use Rector\DeadCode\Rector\Property\RemoveDefaultValueFromAssignedPropertyRector; -use Rector\EarlyReturn\Rector\Foreach_\ChangeNestedForeachIfsToEarlyContinueRector; -use Rector\EarlyReturn\Rector\If_\ChangeIfElseValueAssignToEarlyReturnRector; -use Rector\EarlyReturn\Rector\If_\RemoveAlwaysElseRector; -use Rector\EarlyReturn\Rector\Return_\PreparedValueToEarlyReturnRector; use Rector\Php70\Rector\FuncCall\RandomFunctionRector; use Rector\Php71\Rector\FuncCall\RemoveExtraParametersRector; use Rector\Php80\Rector\Class_\ClassPropertyAssignToConstructorPromotionRector; @@ -37,7 +33,6 @@ use Rector\Privatization\Rector\Class_\FinalizeTestCaseClassRector; use Rector\Privatization\Rector\Property\PrivatizeFinalClassPropertyRector; use Rector\Renaming\Rector\ConstFetch\RenameConstantRector; -use Rector\Strict\Rector\Empty_\DisallowedEmptyRuleFixerRector; use Rector\TypeDeclaration\Rector\ArrowFunction\AddArrowFunctionReturnTypeRector; use Rector\TypeDeclaration\Rector\ClassMethod\AddMethodCallBasedStrictParamTypeRector; use Rector\TypeDeclaration\Rector\ClassMethod\ReturnNeverTypeRector; @@ -179,15 +174,10 @@ DeclareStrictTypesRector::class, UnderscoreToCamelCaseVariableNameRector::class, SimplifyUselessVariableRector::class, - RemoveAlwaysElseRector::class, PassStrictParameterToFunctionParameterRector::class, - ChangeNestedForeachIfsToEarlyContinueRector::class, - ChangeIfElseValueAssignToEarlyReturnRector::class, - PreparedValueToEarlyReturnRector::class, RemoveErrorSuppressInTryCatchStmtsRector::class, FuncGetArgsToVariadicParamRector::class, MakeInheritedMethodVisibilitySameAsParentRector::class, - DisallowedEmptyRuleFixerRector::class, PrivatizeFinalClassPropertyRector::class, VersionCompareFuncCallToConstantRector::class, AddClosureVoidReturnTypeWhereNoReturnRector::class, diff --git a/system/CLI/InputOutput.php b/system/CLI/InputOutput.php index b69c19e2eee1..6ed3b8f36138 100644 --- a/system/CLI/InputOutput.php +++ b/system/CLI/InputOutput.php @@ -51,7 +51,7 @@ public function input(?string $prefix = null): string $input = fgets(fopen('php://stdin', 'rb')); if ($input === false) { - $input = ''; + return ''; } return $input; diff --git a/system/Config/DotEnv.php b/system/Config/DotEnv.php index a820f42824f3..17c74d380c5c 100644 --- a/system/Config/DotEnv.php +++ b/system/Config/DotEnv.php @@ -204,7 +204,7 @@ protected function sanitizeValue(string $value): string protected function resolveNestedVariables(string $value): string { if (str_contains($value, '$')) { - $value = preg_replace_callback( + return preg_replace_callback( '/\${([a-zA-Z0-9_\.]+)}/', function ($matchedPatterns) { $nestedVariable = $this->getVariable($matchedPatterns[1]); diff --git a/system/Database/Postgre/Builder.php b/system/Database/Postgre/Builder.php index ee0a59c63bb1..4723a58e7cc8 100644 --- a/system/Database/Postgre/Builder.php +++ b/system/Database/Postgre/Builder.php @@ -57,7 +57,7 @@ protected function compileIgnore(string $statement) $sql = parent::compileIgnore($statement); if ($sql !== '') { - $sql = ' ' . trim($sql); + return ' ' . trim($sql); } return $sql; diff --git a/system/Files/File.php b/system/Files/File.php index 38eae2ebb6de..feda0cd5780d 100644 --- a/system/Files/File.php +++ b/system/Files/File.php @@ -218,7 +218,7 @@ private function getSizeByUnitInternal(int $fileSizeBase, FileSizeUnit $unit, in $size = $this->getSize() / $divider; if ($unit !== FileSizeUnit::B) { - $size = number_format($size, $precision); + return number_format($size, $precision); } return $size; diff --git a/system/HTTP/ResponseTrait.php b/system/HTTP/ResponseTrait.php index d67a05765e0e..95e58b01a05d 100644 --- a/system/HTTP/ResponseTrait.php +++ b/system/HTTP/ResponseTrait.php @@ -224,7 +224,7 @@ public function getXML() $body = $this->body; if ($this->bodyFormat !== 'xml') { - $body = service('format')->getFormatter('application/xml')->format($body); + return service('format')->getFormatter('application/xml')->format($body); } return $body; @@ -249,7 +249,7 @@ protected function formatBody($body, string $format) // Nothing much to do for a string... if (! is_string($body) || $format === 'json-unencoded') { - $body = service('format')->getFormatter($mime)->format($body); + return service('format')->getFormatter($mime)->format($body); } return $body; diff --git a/system/HTTP/SiteURI.php b/system/HTTP/SiteURI.php index 7d07eff4aeeb..403269008e56 100644 --- a/system/HTTP/SiteURI.php +++ b/system/HTTP/SiteURI.php @@ -188,7 +188,7 @@ private function getIndexPageRoutePath(string $routePath): string $indexPageRoutePath = $indexPage . $routePath; if ($indexPageRoutePath === '/') { - $indexPageRoutePath = ''; + return ''; } return $indexPageRoutePath; @@ -420,7 +420,7 @@ public function baseUrl($relativePath = '', ?string $scheme = null): string private function stringifyRelativePath($relativePath): string { if (is_array($relativePath)) { - $relativePath = implode('/', $relativePath); + return implode('/', $relativePath); } return $relativePath; diff --git a/system/Helpers/url_helper.php b/system/Helpers/url_helper.php index 0b3fa5f72c9c..7ccab202e4ce 100644 --- a/system/Helpers/url_helper.php +++ b/system/Helpers/url_helper.php @@ -423,7 +423,7 @@ function prep_url(string $str = '', bool $secure = false): string // force replace http:// with https:// if ($secure) { - $str = preg_replace('/^(?:http):/i', 'https:', $str); + return preg_replace('/^(?:http):/i', 'https:', $str); } return $str; diff --git a/system/Honeypot/Honeypot.php b/system/Honeypot/Honeypot.php index badf1d719b53..4a40a8ec232a 100644 --- a/system/Honeypot/Honeypot.php +++ b/system/Honeypot/Honeypot.php @@ -111,7 +111,7 @@ protected function prepareTemplate(string $template): string $template = str_ireplace('{name}', $this->config->name, $template); if ($this->config->hidden) { - $template = str_ireplace('{template}', $template, $this->config->container); + return str_ireplace('{template}', $template, $this->config->container); } return $template; diff --git a/system/I18n/TimeTrait.php b/system/I18n/TimeTrait.php index 3189c2076f0a..588162b6f093 100644 --- a/system/I18n/TimeTrait.php +++ b/system/I18n/TimeTrait.php @@ -1157,7 +1157,7 @@ public function getUTCObject($time, ?string $timezone = null) } if ($time instanceof DateTime || $time instanceof DateTimeImmutable) { - $time = $time->setTimezone(new DateTimeZone('UTC')); + return $time->setTimezone(new DateTimeZone('UTC')); } return $time; diff --git a/system/Router/RouteCollection.php b/system/Router/RouteCollection.php index b5bd4ee76597..3eb9a5b5f101 100644 --- a/system/Router/RouteCollection.php +++ b/system/Router/RouteCollection.php @@ -1474,7 +1474,7 @@ private function processArrayCallableSyntax(string $from, array $to): string && is_callable($to[0], true, $callableName) && is_string($to[1]) ) { - $to = '\\' . $callableName . '/' . $to[1]; + return '\\' . $callableName . '/' . $to[1]; } return $to; diff --git a/system/Test/Mock/MockConnection.php b/system/Test/Mock/MockConnection.php index e19e635568ea..18a3eda45d63 100644 --- a/system/Test/Mock/MockConnection.php +++ b/system/Test/Mock/MockConnection.php @@ -128,7 +128,7 @@ public function connect(bool $persistent = false) if (is_array($return)) { // By removing the top item here, we can // get a different value for, say, testing failover connections. - $return = array_shift($this->returnValues['connect']); + return array_shift($this->returnValues['connect']); } return $return; From bac44e91272e4d7cbc7b1b963cd46f8b78aff448 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Sun, 23 Aug 2026 19:44:01 +0700 Subject: [PATCH 2/2] fix return type --- system/Router/RouteCollection.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/system/Router/RouteCollection.php b/system/Router/RouteCollection.php index 3eb9a5b5f101..198168675fad 100644 --- a/system/Router/RouteCollection.php +++ b/system/Router/RouteCollection.php @@ -1455,8 +1455,10 @@ private function checkHostname($hostname): bool /** * @param array $to + * + * @return array|string */ - private function processArrayCallableSyntax(string $from, array $to): string + private function processArrayCallableSyntax(string $from, array $to): array|string { // [classname, method] // eg, [Home::class, 'index']