From 21b88776202eeb57140411c17f7c1627cdc636af Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Thu, 5 Dec 2024 23:58:11 +0700 Subject: [PATCH 1/3] refactor: Apply code quality level 27 for rector --- rector.php | 2 +- system/Commands/Generators/ModelGenerator.php | 2 +- system/Commands/Translation/LocalizationFinder.php | 6 +++--- system/Test/Fabricator.php | 6 +++--- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/rector.php b/rector.php index 64abc9a73541..5058e5f2ab70 100644 --- a/rector.php +++ b/rector.php @@ -210,4 +210,4 @@ // keep '\\' prefix string on string '\Foo\Bar' StringClassNameToClassConstantRector::SHOULD_KEEP_PRE_SLASH => true, ]) - ->withCodeQualityLevel(24); + ->withCodeQualityLevel(27); diff --git a/system/Commands/Generators/ModelGenerator.php b/system/Commands/Generators/ModelGenerator.php index 5450bda79b4c..f611b52f028a 100644 --- a/system/Commands/Generators/ModelGenerator.php +++ b/system/Commands/Generators/ModelGenerator.php @@ -130,6 +130,6 @@ protected function prepare(string $class): string $return = "'{$return}'"; } - return $this->parseTemplate($class, ['{dbGroup}', '{table}', '{return}'], [$dbGroup, $table, $return], compact('dbGroup')); + return $this->parseTemplate($class, ['{dbGroup}', '{table}', '{return}'], [$dbGroup, $table, $return], ['dbGroup' => $dbGroup]); } } diff --git a/system/Commands/Translation/LocalizationFinder.php b/system/Commands/Translation/LocalizationFinder.php index e7d4eff69663..7010fb8c74c2 100644 --- a/system/Commands/Translation/LocalizationFinder.php +++ b/system/Commands/Translation/LocalizationFinder.php @@ -195,7 +195,7 @@ private function findTranslationsInFile($file): array preg_match_all('/lang\(\'([._a-z0-9\-]+)\'\)/ui', $fileContent, $matches); if ($matches[1] === []) { - return compact('foundLanguageKeys', 'badLanguageKeys'); + return ['foundLanguageKeys' => $foundLanguageKeys, 'badLanguageKeys' => $badLanguageKeys]; } foreach ($matches[1] as $phraseKey) { @@ -228,7 +228,7 @@ private function findTranslationsInFile($file): array } } - return compact('foundLanguageKeys', 'badLanguageKeys'); + return ['foundLanguageKeys' => $foundLanguageKeys, 'badLanguageKeys' => $badLanguageKeys]; } private function isIgnoredFile(SplFileInfo $file): bool @@ -384,6 +384,6 @@ private function findLanguageKeysInFiles(array $files): array $badLanguageKeys = array_merge($findInFile['badLanguageKeys'], $badLanguageKeys); } - return compact('foundLanguageKeys', 'badLanguageKeys', 'countFiles'); + return ['foundLanguageKeys' => $foundLanguageKeys, 'badLanguageKeys' => $badLanguageKeys, 'countFiles' => $countFiles]; } } diff --git a/system/Test/Fabricator.php b/system/Test/Fabricator.php index 8da0c60fc089..c34213c5cf6b 100644 --- a/system/Test/Fabricator.php +++ b/system/Test/Fabricator.php @@ -272,7 +272,7 @@ public function setOverrides(array $overrides = [], $persist = true): self */ public function setUnique(string $field, bool $reset = false, int $maxRetries = 10000): static { - $this->modifiedFields['unique'][$field] = compact('reset', 'maxRetries'); + $this->modifiedFields['unique'][$field] = ['reset' => $reset, 'maxRetries' => $maxRetries]; return $this; } @@ -284,7 +284,7 @@ public function setUnique(string $field, bool $reset = false, int $maxRetries = */ public function setOptional(string $field, float $weight = 0.5, mixed $default = null): static { - $this->modifiedFields['optional'][$field] = compact('weight', 'default'); + $this->modifiedFields['optional'][$field] = ['weight' => $weight, 'default' => $default]; return $this; } @@ -298,7 +298,7 @@ public function setOptional(string $field, float $weight = 0.5, mixed $default = */ public function setValid(string $field, ?Closure $validator = null, int $maxRetries = 10000): static { - $this->modifiedFields['valid'][$field] = compact('validator', 'maxRetries'); + $this->modifiedFields['valid'][$field] = ['validator' => $validator, 'maxRetries' => $maxRetries]; return $this; } From 37e63299f5c39d99f990c3ad984d3aaab59f17d2 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Sat, 7 Dec 2024 17:42:53 +0700 Subject: [PATCH 2/3] refactor: skip CompactToVariablesRector --- rector.php | 3 +++ system/Commands/Generators/ModelGenerator.php | 2 +- system/Commands/Translation/LocalizationFinder.php | 6 +++--- system/Test/Fabricator.php | 6 +++--- 4 files changed, 10 insertions(+), 7 deletions(-) diff --git a/rector.php b/rector.php index 5058e5f2ab70..6dd90292df7f 100644 --- a/rector.php +++ b/rector.php @@ -17,6 +17,7 @@ use Rector\CodeQuality\Rector\Expression\InlineIfToExplicitIfRector; use Rector\CodeQuality\Rector\Foreach_\UnusedForeachValueToArrayKeysRector; use Rector\CodeQuality\Rector\FuncCall\ChangeArrayPushToArrayAssignRector; +use Rector\CodeQuality\Rector\FuncCall\CompactToVariablesRector; use Rector\CodeQuality\Rector\FunctionLike\SimplifyUselessVariableRector; use Rector\CodeQuality\Rector\Identical\FlipTypeControlToUseExclusiveTypeRector; use Rector\CodeQuality\Rector\If_\ShortenElseIfRector; @@ -171,6 +172,8 @@ // Unnecessary (string) is inserted NullToStrictStringFuncCallArgRector::class, + + CompactToVariablesRector::class, ]) // auto import fully qualified class names ->withImportNames(removeUnusedImports: true) diff --git a/system/Commands/Generators/ModelGenerator.php b/system/Commands/Generators/ModelGenerator.php index f611b52f028a..5450bda79b4c 100644 --- a/system/Commands/Generators/ModelGenerator.php +++ b/system/Commands/Generators/ModelGenerator.php @@ -130,6 +130,6 @@ protected function prepare(string $class): string $return = "'{$return}'"; } - return $this->parseTemplate($class, ['{dbGroup}', '{table}', '{return}'], [$dbGroup, $table, $return], ['dbGroup' => $dbGroup]); + return $this->parseTemplate($class, ['{dbGroup}', '{table}', '{return}'], [$dbGroup, $table, $return], compact('dbGroup')); } } diff --git a/system/Commands/Translation/LocalizationFinder.php b/system/Commands/Translation/LocalizationFinder.php index 7010fb8c74c2..e7d4eff69663 100644 --- a/system/Commands/Translation/LocalizationFinder.php +++ b/system/Commands/Translation/LocalizationFinder.php @@ -195,7 +195,7 @@ private function findTranslationsInFile($file): array preg_match_all('/lang\(\'([._a-z0-9\-]+)\'\)/ui', $fileContent, $matches); if ($matches[1] === []) { - return ['foundLanguageKeys' => $foundLanguageKeys, 'badLanguageKeys' => $badLanguageKeys]; + return compact('foundLanguageKeys', 'badLanguageKeys'); } foreach ($matches[1] as $phraseKey) { @@ -228,7 +228,7 @@ private function findTranslationsInFile($file): array } } - return ['foundLanguageKeys' => $foundLanguageKeys, 'badLanguageKeys' => $badLanguageKeys]; + return compact('foundLanguageKeys', 'badLanguageKeys'); } private function isIgnoredFile(SplFileInfo $file): bool @@ -384,6 +384,6 @@ private function findLanguageKeysInFiles(array $files): array $badLanguageKeys = array_merge($findInFile['badLanguageKeys'], $badLanguageKeys); } - return ['foundLanguageKeys' => $foundLanguageKeys, 'badLanguageKeys' => $badLanguageKeys, 'countFiles' => $countFiles]; + return compact('foundLanguageKeys', 'badLanguageKeys', 'countFiles'); } } diff --git a/system/Test/Fabricator.php b/system/Test/Fabricator.php index c34213c5cf6b..8da0c60fc089 100644 --- a/system/Test/Fabricator.php +++ b/system/Test/Fabricator.php @@ -272,7 +272,7 @@ public function setOverrides(array $overrides = [], $persist = true): self */ public function setUnique(string $field, bool $reset = false, int $maxRetries = 10000): static { - $this->modifiedFields['unique'][$field] = ['reset' => $reset, 'maxRetries' => $maxRetries]; + $this->modifiedFields['unique'][$field] = compact('reset', 'maxRetries'); return $this; } @@ -284,7 +284,7 @@ public function setUnique(string $field, bool $reset = false, int $maxRetries = */ public function setOptional(string $field, float $weight = 0.5, mixed $default = null): static { - $this->modifiedFields['optional'][$field] = ['weight' => $weight, 'default' => $default]; + $this->modifiedFields['optional'][$field] = compact('weight', 'default'); return $this; } @@ -298,7 +298,7 @@ public function setOptional(string $field, float $weight = 0.5, mixed $default = */ public function setValid(string $field, ?Closure $validator = null, int $maxRetries = 10000): static { - $this->modifiedFields['valid'][$field] = ['validator' => $validator, 'maxRetries' => $maxRetries]; + $this->modifiedFields['valid'][$field] = compact('validator', 'maxRetries'); return $this; } From 608b869a20c1848c51e2325ad82fa4a96391336e Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Sat, 7 Dec 2024 17:46:25 +0700 Subject: [PATCH 3/3] refactor: enable level 31: ThrowWithPreviousExceptionRector --- rector.php | 4 +--- system/Security/Security.php | 2 +- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/rector.php b/rector.php index 6dd90292df7f..4613f89fbe3c 100644 --- a/rector.php +++ b/rector.php @@ -12,7 +12,6 @@ */ use Rector\Caching\ValueObject\Storage\FileCacheStorage; -use Rector\CodeQuality\Rector\Class_\CompleteDynamicPropertiesRector; use Rector\CodeQuality\Rector\Empty_\SimplifyEmptyCheckOnEmptyArrayRector; use Rector\CodeQuality\Rector\Expression\InlineIfToExplicitIfRector; use Rector\CodeQuality\Rector\Foreach_\UnusedForeachValueToArrayKeysRector; @@ -199,7 +198,6 @@ EmptyOnNullableObjectToInstanceOfRector::class, DisallowedEmptyRuleFixerRector::class, PrivatizeFinalClassPropertyRector::class, - CompleteDynamicPropertiesRector::class, BooleanInIfConditionRuleFixerRector::class, VersionCompareFuncCallToConstantRector::class, AddClosureVoidReturnTypeWhereNoReturnRector::class, @@ -213,4 +211,4 @@ // keep '\\' prefix string on string '\Foo\Bar' StringClassNameToClassConstantRector::SHOULD_KEEP_PRE_SLASH => true, ]) - ->withCodeQualityLevel(27); + ->withCodeQualityLevel(31); diff --git a/system/Security/Security.php b/system/Security/Security.php index 0b51062e4cdb..4d4d856cc1d8 100644 --- a/system/Security/Security.php +++ b/system/Security/Security.php @@ -377,7 +377,7 @@ protected function derandomize(string $token): string return bin2hex(hex2bin($value) ^ hex2bin($key)); } catch (ErrorException $e) { // "hex2bin(): Hexadecimal input string must have an even length" - throw new InvalidArgumentException($e->getMessage()); + throw new InvalidArgumentException($e->getMessage(), $e->getCode(), $e); } }