chore: [Rector] Apply ExplicitBoolCompareRector

This commit is contained in:
Abdul Malik Ikhsan 2024-04-03 22:25:35 +07:00
parent 518b912838
commit 0987c9ac0b
No known key found for this signature in database
GPG Key ID: 69AC5BC354C89BE6
16 changed files with 25 additions and 153 deletions

View File

@ -446,16 +446,6 @@ $ignoreErrors[] = [
'count' => 1,
'path' => __DIR__ . '/system/CLI/CLI.php',
];
$ignoreErrors[] = [
'message' => '#^Only booleans are allowed in a negated boolean, array given\\.$#',
'count' => 1,
'path' => __DIR__ . '/system/CLI/CLI.php',
];
$ignoreErrors[] = [
'message' => '#^Only booleans are allowed in a ternary operator condition, string given\\.$#',
'count' => 1,
'path' => __DIR__ . '/system/CLI/CLI.php',
];
$ignoreErrors[] = [
'message' => '#^Only booleans are allowed in a ternary operator condition, string\\|null given\\.$#',
'count' => 1,
@ -766,11 +756,6 @@ $ignoreErrors[] = [
'count' => 1,
'path' => __DIR__ . '/system/Commands/Database/MigrateStatus.php',
];
$ignoreErrors[] = [
'message' => '#^Only booleans are allowed in a negated boolean, array\\<int\\<0, max\\>, array\\<int, mixed\\>\\> given\\.$#',
'count' => 1,
'path' => __DIR__ . '/system/Commands/Database/MigrateStatus.php',
];
$ignoreErrors[] = [
'message' => '#^Parameter \\#1 \\$params \\(array\\<string, mixed\\>\\) of method CodeIgniter\\\\Commands\\\\Database\\\\MigrateStatus\\:\\:run\\(\\) should be contravariant with parameter \\$params \\(array\\<int\\|string, string\\|null\\>\\) of method CodeIgniter\\\\CLI\\\\BaseCommand\\:\\:run\\(\\)$#',
'count' => 1,
@ -2131,11 +2116,6 @@ $ignoreErrors[] = [
'count' => 1,
'path' => __DIR__ . '/system/Config/DotEnv.php',
];
$ignoreErrors[] = [
'message' => '#^Only booleans are allowed in a negated boolean, string given\\.$#',
'count' => 1,
'path' => __DIR__ . '/system/Config/DotEnv.php',
];
$ignoreErrors[] = [
'message' => '#^Method CodeIgniter\\\\Config\\\\Factories\\:\\:__callStatic\\(\\) has parameter \\$arguments with no value type specified in iterable type array\\.$#',
'count' => 1,
@ -2286,11 +2266,6 @@ $ignoreErrors[] = [
'count' => 1,
'path' => __DIR__ . '/system/Controller.php',
];
$ignoreErrors[] = [
'message' => '#^Only booleans are allowed in a negated boolean, array given\\.$#',
'count' => 1,
'path' => __DIR__ . '/system/Controller.php',
];
$ignoreErrors[] = [
'message' => '#^Property CodeIgniter\\\\Controller\\:\\:\\$request \\(CodeIgniter\\\\HTTP\\\\CLIRequest\\|CodeIgniter\\\\HTTP\\\\IncomingRequest\\) does not accept CodeIgniter\\\\HTTP\\\\RequestInterface\\.$#',
'count' => 1,
@ -3731,11 +3706,6 @@ $ignoreErrors[] = [
'count' => 1,
'path' => __DIR__ . '/system/Database/OCI8/Builder.php',
];
$ignoreErrors[] = [
'message' => '#^Only booleans are allowed in a ternary operator condition, int given\\.$#',
'count' => 1,
'path' => __DIR__ . '/system/Database/OCI8/Builder.php',
];
$ignoreErrors[] = [
'message' => '#^PHPDoc type CodeIgniter\\\\Database\\\\OCI8\\\\Connection of property CodeIgniter\\\\Database\\\\OCI8\\\\Builder\\:\\:\\$db is not the same as PHPDoc type CodeIgniter\\\\Database\\\\BaseConnection of overridden property CodeIgniter\\\\Database\\\\BaseBuilder\\:\\:\\$db\\.$#',
'count' => 1,
@ -6216,11 +6186,6 @@ $ignoreErrors[] = [
'count' => 1,
'path' => __DIR__ . '/system/HTTP/DownloadResponse.php',
];
$ignoreErrors[] = [
'message' => '#^Only booleans are allowed in an if condition, string given\\.$#',
'count' => 1,
'path' => __DIR__ . '/system/HTTP/DownloadResponse.php',
];
$ignoreErrors[] = [
'message' => '#^Return type \\(CodeIgniter\\\\HTTP\\\\DownloadResponse\\) of method CodeIgniter\\\\HTTP\\\\DownloadResponse\\:\\:sendBody\\(\\) should be covariant with return type \\(\\$this\\(CodeIgniter\\\\HTTP\\\\Response\\)\\) of method CodeIgniter\\\\HTTP\\\\Response\\:\\:sendBody\\(\\)$#',
'count' => 1,
@ -7116,66 +7081,6 @@ $ignoreErrors[] = [
'count' => 1,
'path' => __DIR__ . '/system/Helpers/filesystem_helper.php',
];
$ignoreErrors[] = [
'message' => '#^Only booleans are allowed in a ternary operator condition, int\\<0, 1024\\> given\\.$#',
'count' => 2,
'path' => __DIR__ . '/system/Helpers/filesystem_helper.php',
];
$ignoreErrors[] = [
'message' => '#^Only booleans are allowed in a ternary operator condition, int\\<0, 128\\> given\\.$#',
'count' => 1,
'path' => __DIR__ . '/system/Helpers/filesystem_helper.php',
];
$ignoreErrors[] = [
'message' => '#^Only booleans are allowed in a ternary operator condition, int\\<0, 16\\> given\\.$#',
'count' => 1,
'path' => __DIR__ . '/system/Helpers/filesystem_helper.php',
];
$ignoreErrors[] = [
'message' => '#^Only booleans are allowed in a ternary operator condition, int\\<0, 1\\> given\\.$#',
'count' => 1,
'path' => __DIR__ . '/system/Helpers/filesystem_helper.php',
];
$ignoreErrors[] = [
'message' => '#^Only booleans are allowed in a ternary operator condition, int\\<0, 2048\\> given\\.$#',
'count' => 2,
'path' => __DIR__ . '/system/Helpers/filesystem_helper.php',
];
$ignoreErrors[] = [
'message' => '#^Only booleans are allowed in a ternary operator condition, int\\<0, 256\\> given\\.$#',
'count' => 1,
'path' => __DIR__ . '/system/Helpers/filesystem_helper.php',
];
$ignoreErrors[] = [
'message' => '#^Only booleans are allowed in a ternary operator condition, int\\<0, 2\\> given\\.$#',
'count' => 1,
'path' => __DIR__ . '/system/Helpers/filesystem_helper.php',
];
$ignoreErrors[] = [
'message' => '#^Only booleans are allowed in a ternary operator condition, int\\<0, 32\\> given\\.$#',
'count' => 1,
'path' => __DIR__ . '/system/Helpers/filesystem_helper.php',
];
$ignoreErrors[] = [
'message' => '#^Only booleans are allowed in a ternary operator condition, int\\<0, 4\\> given\\.$#',
'count' => 1,
'path' => __DIR__ . '/system/Helpers/filesystem_helper.php',
];
$ignoreErrors[] = [
'message' => '#^Only booleans are allowed in a ternary operator condition, int\\<0, 512\\> given\\.$#',
'count' => 2,
'path' => __DIR__ . '/system/Helpers/filesystem_helper.php',
];
$ignoreErrors[] = [
'message' => '#^Only booleans are allowed in a ternary operator condition, int\\<0, 64\\> given\\.$#',
'count' => 1,
'path' => __DIR__ . '/system/Helpers/filesystem_helper.php',
];
$ignoreErrors[] = [
'message' => '#^Only booleans are allowed in a ternary operator condition, int\\<0, 8\\> given\\.$#',
'count' => 1,
'path' => __DIR__ . '/system/Helpers/filesystem_helper.php',
];
$ignoreErrors[] = [
'message' => '#^Right side of && is always true\\.$#',
'count' => 1,
@ -7386,11 +7291,6 @@ $ignoreErrors[] = [
'count' => 1,
'path' => __DIR__ . '/system/Helpers/form_helper.php',
];
$ignoreErrors[] = [
'message' => '#^Only booleans are allowed in a negated boolean, string given\\.$#',
'count' => 1,
'path' => __DIR__ . '/system/Helpers/form_helper.php',
];
$ignoreErrors[] = [
'message' => '#^Function _list\\(\\) has parameter \\$attributes with no value type specified in iterable type array\\.$#',
'count' => 1,
@ -7471,11 +7371,6 @@ $ignoreErrors[] = [
'count' => 1,
'path' => __DIR__ . '/system/Helpers/html_helper.php',
];
$ignoreErrors[] = [
'message' => '#^Only booleans are allowed in a ternary operator condition, string given\\.$#',
'count' => 1,
'path' => __DIR__ . '/system/Helpers/html_helper.php',
];
$ignoreErrors[] = [
'message' => '#^Function d\\(\\) has parameter \\$vars with no value type specified in iterable type array\\.$#',
'count' => 1,
@ -7576,11 +7471,6 @@ $ignoreErrors[] = [
'count' => 1,
'path' => __DIR__ . '/system/Helpers/url_helper.php',
];
$ignoreErrors[] = [
'message' => '#^Only booleans are allowed in a ternary operator condition, string given\\.$#',
'count' => 1,
'path' => __DIR__ . '/system/Helpers/url_helper.php',
];
$ignoreErrors[] = [
'message' => '#^Variable \\$atts might not be defined\\.$#',
'count' => 1,
@ -8386,11 +8276,6 @@ $ignoreErrors[] = [
'count' => 1,
'path' => __DIR__ . '/system/Router/RouteCollection.php',
];
$ignoreErrors[] = [
'message' => '#^Only booleans are allowed in a ternary operator condition, string given\\.$#',
'count' => 1,
'path' => __DIR__ . '/system/Router/RouteCollection.php',
];
$ignoreErrors[] = [
'message' => '#^Only booleans are allowed in a ternary operator condition, string\\|null given\\.$#',
'count' => 1,
@ -8641,11 +8526,6 @@ $ignoreErrors[] = [
'count' => 1,
'path' => __DIR__ . '/system/Session/Handlers/FileHandler.php',
];
$ignoreErrors[] = [
'message' => '#^Only booleans are allowed in a negated boolean, string given\\.$#',
'count' => 1,
'path' => __DIR__ . '/system/Session/Handlers/FileHandler.php',
];
$ignoreErrors[] = [
'message' => '#^PHPDoc type string of property CodeIgniter\\\\Session\\\\Handlers\\\\FileHandler\\:\\:\\$savePath is not the same as PHPDoc type array\\|string of overridden property CodeIgniter\\\\Session\\\\Handlers\\\\BaseHandler\\:\\:\\$savePath\\.$#',
'count' => 1,
@ -10606,11 +10486,6 @@ $ignoreErrors[] = [
'count' => 1,
'path' => __DIR__ . '/system/View/Table.php',
];
$ignoreErrors[] = [
'message' => '#^Only booleans are allowed in a ternary operator condition, float given\\.$#',
'count' => 1,
'path' => __DIR__ . '/system/View/Table.php',
];
$ignoreErrors[] = [
'message' => '#^Only booleans are allowed in an if condition, string\\|null given\\.$#',
'count' => 1,
@ -12036,11 +11911,6 @@ $ignoreErrors[] = [
'count' => 1,
'path' => __DIR__ . '/tests/system/Cache/ResponseCacheTest.php',
];
$ignoreErrors[] = [
'message' => '#^Only booleans are allowed in a ternary operator condition, array given\\.$#',
'count' => 1,
'path' => __DIR__ . '/tests/system/Cache/ResponseCacheTest.php',
];
$ignoreErrors[] = [
'message' => '#^Re\\-assigning arrays to \\$_GET directly is discouraged\\.$#',
'count' => 3,

View File

@ -21,6 +21,7 @@ use Rector\CodeQuality\Rector\FuncCall\SimplifyStrposLowerRector;
use Rector\CodeQuality\Rector\FuncCall\SingleInArrayToCompareRector;
use Rector\CodeQuality\Rector\FunctionLike\SimplifyUselessVariableRector;
use Rector\CodeQuality\Rector\If_\CombineIfRector;
use Rector\CodeQuality\Rector\If_\ExplicitBoolCompareRector;
use Rector\CodeQuality\Rector\If_\ShortenElseIfRector;
use Rector\CodeQuality\Rector\If_\SimplifyIfElseToTernaryRector;
use Rector\CodeQuality\Rector\If_\SimplifyIfReturnBoolRector;
@ -158,6 +159,7 @@ return static function (RectorConfig $rectorConfig): void {
$rectorConfig->rule(BooleanInIfConditionRuleFixerRector::class);
$rectorConfig->rule(SingleInArrayToCompareRector::class);
$rectorConfig->rule(VersionCompareFuncCallToConstantRector::class);
$rectorConfig->rule(ExplicitBoolCompareRector::class);
$rectorConfig
->ruleWithConfiguration(StringClassNameToClassConstantRector::class, [

View File

@ -262,7 +262,7 @@ class CLI
$default = $options[0];
}
static::fwrite(STDOUT, $field . (trim($field) ? ' ' : '') . $extraOutput . ': ');
static::fwrite(STDOUT, $field . (trim($field) !== '' && trim($field) !== '0' ? ' ' : '') . $extraOutput . ': ');
// Read the input from keyboard.
$input = trim(static::input()) ?: $default;
@ -386,7 +386,7 @@ class CLI
*/
private static function isZeroOptions(array $options): void
{
if (! $options) {
if ($options === []) {
throw new InvalidArgumentException('No options to select from were provided');
}
}

View File

@ -144,7 +144,7 @@ class MigrateStatus extends BaseCommand
}
}
if (! $status) {
if ($status === []) {
// @codeCoverageIgnoreStart
CLI::error(lang('Migrations.noneFound'), 'light_gray', 'red');
CLI::newLine();

View File

@ -140,7 +140,7 @@ class DotEnv
*/
protected function sanitizeValue(string $value): string
{
if (! $value) {
if ($value === '' || $value === '0') {
return $value;
}

View File

@ -187,7 +187,7 @@ class Controller
}
// If no error message is defined, use the error message in the Config\Validation file
if (! $messages) {
if ($messages === []) {
$errorName = $rules . '_errors';
$messages = $validation->{$errorName} ?? [];
}

View File

@ -222,7 +222,7 @@ class Builder extends BaseBuilder
}
$this->limitUsed = true;
$limitTemplateQuery = 'SELECT * FROM (SELECT INNER_QUERY.*, ROWNUM RNUM FROM (%s) INNER_QUERY WHERE ROWNUM < %d)' . ($offset ? ' WHERE RNUM >= %d' : '');
$limitTemplateQuery = 'SELECT * FROM (SELECT INNER_QUERY.*, ROWNUM RNUM FROM (%s) INNER_QUERY WHERE ROWNUM < %d)' . ($offset !== 0 ? ' WHERE RNUM >= %d' : '');
return sprintf($limitTemplateQuery, $sql, $offset + $this->QBLimit + 1, $offset);
}

View File

@ -194,7 +194,7 @@ class DownloadResponse extends Response
$result = sprintf('attachment; filename="%s"', $downloadFilename);
if ($utf8Filename) {
if ($utf8Filename !== '' && $utf8Filename !== '0') {
$result .= '; filename*=UTF-8\'\'' . rawurlencode($utf8Filename);
}

View File

@ -379,19 +379,19 @@ if (! function_exists('symbolic_permissions')) {
}
// Owner
$symbolic .= (($perms & 0x0100) ? 'r' : '-')
. (($perms & 0x0080) ? 'w' : '-')
. (($perms & 0x0040) ? (($perms & 0x0800) ? 's' : 'x') : (($perms & 0x0800) ? 'S' : '-'));
$symbolic .= ((($perms & 0x0100) !== 0) ? 'r' : '-')
. ((($perms & 0x0080) !== 0) ? 'w' : '-')
. ((($perms & 0x0040) !== 0) ? ((($perms & 0x0800) !== 0) ? 's' : 'x') : ((($perms & 0x0800) !== 0) ? 'S' : '-'));
// Group
$symbolic .= (($perms & 0x0020) ? 'r' : '-')
. (($perms & 0x0010) ? 'w' : '-')
. (($perms & 0x0008) ? (($perms & 0x0400) ? 's' : 'x') : (($perms & 0x0400) ? 'S' : '-'));
$symbolic .= ((($perms & 0x0020) !== 0) ? 'r' : '-')
. ((($perms & 0x0010) !== 0) ? 'w' : '-')
. ((($perms & 0x0008) !== 0) ? ((($perms & 0x0400) !== 0) ? 's' : 'x') : ((($perms & 0x0400) !== 0) ? 'S' : '-'));
// World
$symbolic .= (($perms & 0x0004) ? 'r' : '-')
. (($perms & 0x0002) ? 'w' : '-')
. (($perms & 0x0001) ? (($perms & 0x0200) ? 't' : 'x') : (($perms & 0x0200) ? 'T' : '-'));
$symbolic .= ((($perms & 0x0004) !== 0) ? 'r' : '-')
. ((($perms & 0x0002) !== 0) ? 'w' : '-')
. ((($perms & 0x0001) !== 0) ? ((($perms & 0x0200) !== 0) ? 't' : 'x') : ((($perms & 0x0200) !== 0) ? 'T' : '-'));
return $symbolic;
}

View File

@ -29,7 +29,7 @@ if (! function_exists('form_open')) {
function form_open(string $action = '', $attributes = [], array $hidden = []): string
{
// If no action is provided then set to the current url
if (! $action) {
if ($action === '' || $action === '0') {
$action = current_url(true);
} // If an action is not a full URL then turn it into one
elseif (strpos($action, '://') === false) {

View File

@ -195,7 +195,7 @@ if (! function_exists('script_tag')) {
function script_tag($src = '', bool $indexPage = false): string
{
$cspNonce = csp_script_nonce();
$cspNonce = $cspNonce ? ' ' . $cspNonce : $cspNonce;
$cspNonce = $cspNonce !== '' && $cspNonce !== '0' ? ' ' . $cspNonce : $cspNonce;
$script = '<script' . $cspNonce . ' ';
if (! is_array($src)) {
$src = ['src' => $src];

View File

@ -318,7 +318,7 @@ if (! function_exists('safe_mailto')) {
// improve obfuscation by eliminating newlines & whitespace
$cspNonce = csp_script_nonce();
$cspNonce = $cspNonce ? ' ' . $cspNonce : $cspNonce;
$cspNonce = $cspNonce !== '' && $cspNonce !== '0' ? ' ' . $cspNonce : $cspNonce;
$output = '<script' . $cspNonce . '>'
. 'var l=new Array();';

View File

@ -767,7 +767,7 @@ class RouteCollection implements RouteCollectionInterface
// To register a route, we'll set a flag so that our router
// will see the group name.
// If the group name is empty, we go on using the previously built group name.
$this->group = $name ? trim($oldGroup . '/' . $name, '/') : $oldGroup;
$this->group = $name !== '' && $name !== '0' ? trim($oldGroup . '/' . $name, '/') : $oldGroup;
$callback = array_pop($params);

View File

@ -73,7 +73,7 @@ class FileHandler extends BaseHandler
} else {
$sessionPath = rtrim(ini_get('session.save_path'), '/\\');
if (! $sessionPath) {
if ($sessionPath === '' || $sessionPath === '0') {
$sessionPath = WRITEPATH . 'session';
}

View File

@ -365,7 +365,7 @@ class Table
foreach ($this->rows as $row) {
// We use modulus to alternate the row colors
$name = fmod($i++, 2) ? '' : 'alt_';
$name = fmod($i++, 2) !== 0.0 ? '' : 'alt_';
$out .= $this->template['row_' . $name . 'start'] . $this->newline;

View File

@ -48,7 +48,7 @@ final class ResponseCacheTest extends CIUnitTestCase
): IncomingRequest {
$_POST = $_GET = $_SERVER = $_REQUEST = $_ENV = $_COOKIE = $_SESSION = [];
$_SERVER['REQUEST_URI'] = '/' . $uri . ($query ? '?' . http_build_query($query) : '');
$_SERVER['REQUEST_URI'] = '/' . $uri . ($query !== [] ? '?' . http_build_query($query) : '');
$_SERVER['SCRIPT_NAME'] = '/index.php';
$appConfig ??= $this->appConfig;