Skip to content

Commit d842179

Browse files
committed
refactor: enable instanceof and strictBooleans rector set
1 parent cc1b8f2 commit d842179

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+102
-138
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'] ?? [])));

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: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ public static function prompt(string $field, $options = null, $validation = null
230230
}
231231

232232
if (! is_array($validation)) {
233-
$validation = $validation ? explode('|', $validation) : [];
233+
$validation = $validation !== null && $validation !== '' && $validation !== '0' ? explode('|', $validation) : [];
234234
}
235235

236236
if (is_string($options)) {
@@ -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 || $pattern === false || $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 || in_array(preg_match('/^(\.htaccess|index\.(html|htm|php)|web\.config)$/i', $filename), [0, false], true)) {
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 (in_array(getenv($name, true), ['', '0'], true) || getenv($name, true) === [] || 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;

system/Database/BaseBuilder.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1736,7 +1736,7 @@ public function countAllResults(bool $reset = true)
17361736
// Restore the LIMIT setting
17371737
$this->QBLimit = $limit;
17381738

1739-
$row = ! $result instanceof ResultInterface ? null : $result->getRow();
1739+
$row = $result instanceof ResultInterface ? $result->getRow() : null;
17401740

17411741
if (empty($row)) {
17421742
return 0;
@@ -3167,11 +3167,11 @@ protected function compileWhereHaving(string $qbKey): string
31673167
$op = $this->getOperator($condition);
31683168
if (
31693169
$op === false
3170-
|| ! preg_match(
3170+
|| in_array(preg_match(
31713171
'/^(\(?)(.*)(' . preg_quote($op, '/') . ')\s*(.*(?<!\)))?(\)?)$/i',
31723172
$condition,
31733173
$matches
3174-
)
3174+
), [0, false], true)
31753175
) {
31763176
continue;
31773177
}

0 commit comments

Comments
 (0)