Skip to content

Commit ee4ee98

Browse files
authored
refactor: enable instanceof and strictBooleans rector set (#9339)
* refactor: enable instanceof and strictBooleans rector set * refactor: bump to rector 2.0.4 * refactor: clean condition check * refactor: revert ThirdParty change * refactor: re-run phpstan baseline * refactor: fix never empty array on Image * refactor: avoid repetitive call pg_last_error() * refactor: pg_last_error() always returns string * refactor: use return empty string on pg_last_error() got empty "0" * refactor: various compare !== 1 on preg_match() * refactor: use falsy check on getenv() * refactor: more !== 1 compare on preg_match() * refactor: use empty string check on guessExtension * refactor: run cs fix * refactor: more !== 1 compare on preg_match() * use direct result of pg_last_error() * refactor: use str_contains() over strpos on Forge * refactor: fix unused variable * refactor: check empty string on ResponseTrait * refactor: more preg_match() and empty string only check * refactor: compare to 0 on preg_match_all() * refactor: re-run rector * refactor: preg_match_all() likely less to return false
1 parent 8cff099 commit ee4ee98

37 files changed

+63
-99
lines changed

app/Views/errors/cli/error_exception.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252

5353
$args = implode(', ', array_map(static fn ($value) => match (true) {
5454
is_object($value) => 'Object(' . $value::class . ')',
55-
is_array($value) => count($value) ? '[...]' : '[]',
55+
is_array($value) => $value !== [] ? '[...]' : '[]',
5656
$value === null => 'null', // return the lowercased version
5757
default => var_export($value, true),
5858
}, array_values($error['args'] ?? [])));

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
"phpunit/phpcov": "^9.0.2 || ^10.0",
2929
"phpunit/phpunit": "^10.5.16 || ^11.2",
3030
"predis/predis": "^1.1 || ^2.0",
31-
"rector/rector": "2.0.3",
31+
"rector/rector": "2.0.4",
3232
"shipmonk/phpstan-baseline-per-identifier": "^2.0"
3333
},
3434
"replace": {

rector.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
use Rector\Php80\Rector\Class_\ClassPropertyAssignToConstructorPromotionRector;
3939
use Rector\Php81\Rector\FuncCall\NullToStrictStringFuncCallArgRector;
4040
use Rector\PHPUnit\CodeQuality\Rector\Class_\YieldDataProviderRector;
41-
use Rector\PHPUnit\Set\PHPUnitSetList;
4241
use Rector\Privatization\Rector\Property\PrivatizeFinalClassPropertyRector;
4342
use Rector\Strict\Rector\Empty_\DisallowedEmptyRuleFixerRector;
4443
use Rector\Strict\Rector\If_\BooleanInIfConditionRuleFixerRector;
@@ -56,11 +55,8 @@
5655

5756
return RectorConfig::configure()
5857
->withPhpSets(php81: true)
59-
->withPreparedSets(deadCode: true)
60-
->withSets([
61-
PHPUnitSetList::PHPUNIT_CODE_QUALITY,
62-
PHPUnitSetList::PHPUNIT_100,
63-
])
58+
->withPreparedSets(deadCode: true, instanceOf: true, strictBooleans: true, phpunitCodeQuality: true)
59+
->withComposerBased(phpunit: true)
6460
->withParallel(120, 8, 10)
6561
->withCache(
6662
// Github action cache or local

system/CLI/CLI.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ public static function promptByMultipleKeys(string $text, array $options): array
348348
// return the prompt again if $input contain(s) non-numeric character, except a comma.
349349
// And if max from $options less than max from input,
350350
// it means user tried to access null value in $options
351-
if (! $pattern || $maxOptions < $maxInput) {
351+
if ($pattern === 0 || $maxOptions < $maxInput) {
352352
static::error('Please select correctly.');
353353
CLI::newLine();
354354

system/Cache/Handlers/FileHandler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ protected function deleteFiles(string $path, bool $delDir = false, bool $htdocs
308308
if ($filename !== '.' && $filename !== '..') {
309309
if (is_dir($path . DIRECTORY_SEPARATOR . $filename) && $filename[0] !== '.') {
310310
$this->deleteFiles($path . DIRECTORY_SEPARATOR . $filename, $delDir, $htdocs, $_level + 1);
311-
} elseif (! $htdocs || ! preg_match('/^(\.htaccess|index\.(html|htm|php)|web\.config)$/i', $filename)) {
311+
} elseif (! $htdocs || preg_match('/^(\.htaccess|index\.(html|htm|php)|web\.config)$/i', $filename) !== 1) {
312312
@unlink($path . DIRECTORY_SEPARATOR . $filename);
313313
}
314314
}

system/Commands/Utilities/Routes/AutoRouterImproved/ControllerMethodReader.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ private function getRouteForDefaultController(
221221
if ($classShortname === $defaultController) {
222222
$pattern = '#' . preg_quote(lcfirst($defaultController), '#') . '\z#';
223223
$routeWithoutController = rtrim(preg_replace($pattern, '', $uriByClass), '/');
224-
$routeWithoutController = $routeWithoutController ?: '/';
224+
$routeWithoutController = $routeWithoutController !== '' && $routeWithoutController !== '0' ? $routeWithoutController : '/';
225225

226226
[$params, $routeParams] = $this->getParameters($method);
227227

system/Commands/Utilities/Routes/ControllerMethodReader.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ private function getRouteWithoutController(
161161

162162
$pattern = '#' . preg_quote(lcfirst($defaultController), '#') . '\z#';
163163
$routeWithoutController = rtrim(preg_replace($pattern, '', $uriByClass), '/');
164-
$routeWithoutController = $routeWithoutController ?: '/';
164+
$routeWithoutController = $routeWithoutController !== '' && $routeWithoutController !== '0' ? $routeWithoutController : '/';
165165

166166
return [[
167167
'route' => $routeWithoutController,

system/Config/DotEnv.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public function parse(): ?array
9494
*/
9595
protected function setVariable(string $name, string $value = '')
9696
{
97-
if (! getenv($name, true)) {
97+
if (getenv($name, true) === false) {
9898
putenv("{$name}={$value}");
9999
}
100100

system/Config/Services.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ public static function image(?string $handler = null, ?Images $config = null, bo
345345
$config ??= config(Images::class);
346346
assert($config instanceof Images);
347347

348-
$handler = $handler ?: $config->defaultHandler;
348+
$handler = $handler !== null && $handler !== '' && $handler !== '0' ? $handler : $config->defaultHandler;
349349
$class = $config->handlers[$handler];
350350

351351
return new $class($config);
@@ -385,7 +385,7 @@ public static function language(?string $locale = null, bool $getShared = true)
385385
}
386386

387387
// Use '?:' for empty string check
388-
$locale = $locale ?: $requestLocale;
388+
$locale = $locale !== null && $locale !== '' && $locale !== '0' ? $locale : $requestLocale;
389389

390390
return new Language($locale);
391391
}
@@ -484,7 +484,7 @@ public static function parser(?string $viewPath = null, ?ViewConfig $config = nu
484484
return static::getSharedInstance('parser', $viewPath, $config);
485485
}
486486

487-
$viewPath = $viewPath ?: (new Paths())->viewDirectory;
487+
$viewPath = $viewPath !== null && $viewPath !== '' && $viewPath !== '0' ? $viewPath : (new Paths())->viewDirectory;
488488
$config ??= config(ViewConfig::class);
489489

490490
return new Parser($config, $viewPath, AppServices::get('locator'), CI_DEBUG, AppServices::get('logger'));
@@ -503,7 +503,7 @@ public static function renderer(?string $viewPath = null, ?ViewConfig $config =
503503
return static::getSharedInstance('renderer', $viewPath, $config);
504504
}
505505

506-
$viewPath = $viewPath ?: (new Paths())->viewDirectory;
506+
$viewPath = $viewPath !== null && $viewPath !== '' && $viewPath !== '0' ? $viewPath : (new Paths())->viewDirectory;
507507
$config ??= config(ViewConfig::class);
508508

509509
return new View($config, $viewPath, AppServices::get('locator'), CI_DEBUG, AppServices::get('logger'));

system/Cookie/Cookie.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,7 @@ public function withNeverExpiring()
482482
*/
483483
public function withPath(?string $path)
484484
{
485-
$path = $path ?: self::$defaults['path'];
485+
$path = $path !== null && $path !== '' && $path !== '0' ? $path : self::$defaults['path'];
486486
$this->validatePrefix($this->prefix, $this->secure, $path, $this->domain);
487487

488488
$cookie = clone $this;

0 commit comments

Comments
 (0)