Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: [Rector] Apply ExplicitBoolCompareRector #8704

Merged
merged 2 commits into from
Apr 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
130 changes: 0 additions & 130 deletions phpstan-baseline.php
Original file line number Diff line number Diff line change
Expand Up @@ -446,16 +446,6 @@
'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,
Expand Down Expand Up @@ -766,11 +756,6 @@
'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,
Expand Down Expand Up @@ -2131,11 +2116,6 @@
'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,
Expand Down Expand Up @@ -2286,11 +2266,6 @@
'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,
Expand Down Expand Up @@ -3731,11 +3706,6 @@
'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,
Expand Down Expand Up @@ -6216,11 +6186,6 @@
'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,
Expand Down Expand Up @@ -7116,66 +7081,6 @@
'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,
Expand Down Expand Up @@ -7386,11 +7291,6 @@
'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,
Expand Down Expand Up @@ -7471,11 +7371,6 @@
'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,
Expand Down Expand Up @@ -7576,11 +7471,6 @@
'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,
Expand Down Expand Up @@ -8386,11 +8276,6 @@
'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,
Expand Down Expand Up @@ -8641,11 +8526,6 @@
'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,
Expand Down Expand Up @@ -10606,11 +10486,6 @@
'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,
Expand Down Expand Up @@ -12036,11 +11911,6 @@
'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,
Expand Down
2 changes: 2 additions & 0 deletions rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
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;
Expand Down Expand Up @@ -158,6 +159,7 @@
$rectorConfig->rule(BooleanInIfConditionRuleFixerRector::class);
$rectorConfig->rule(SingleInArrayToCompareRector::class);
$rectorConfig->rule(VersionCompareFuncCallToConstantRector::class);
$rectorConfig->rule(ExplicitBoolCompareRector::class);

$rectorConfig
->ruleWithConfiguration(StringClassNameToClassConstantRector::class, [
Expand Down
4 changes: 2 additions & 2 deletions system/CLI/CLI.php
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ public static function prompt(string $field, $options = null, $validation = null
$default = $options[0];
}

static::fwrite(STDOUT, $field . (trim($field) ? ' ' : '') . $extraOutput . ': ');
static::fwrite(STDOUT, $field . (trim($field) !== '' ? ' ' : '') . $extraOutput . ': ');

// Read the input from keyboard.
$input = trim(static::input()) ?: $default;
Expand Down Expand Up @@ -386,7 +386,7 @@ public static function promptByMultipleKeys(string $text, array $options): array
*/
private static function isZeroOptions(array $options): void
{
if (! $options) {
if ($options === []) {
throw new InvalidArgumentException('No options to select from were provided');
}
}
Expand Down
2 changes: 1 addition & 1 deletion system/Commands/Database/MigrateStatus.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ public function run(array $params)
}
}

if (! $status) {
if ($status === []) {
// @codeCoverageIgnoreStart
CLI::error(lang('Migrations.noneFound'), 'light_gray', 'red');
CLI::newLine();
Expand Down
2 changes: 1 addition & 1 deletion system/Config/DotEnv.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ public function normaliseVariable(string $name, string $value = ''): array
*/
protected function sanitizeValue(string $value): string
{
if (! $value) {
if ($value === '') {
return $value;
}

Expand Down
2 changes: 1 addition & 1 deletion system/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ private function setValidator($rules, array $messages): void
}

// 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} ?? [];
}
Expand Down
2 changes: 1 addition & 1 deletion system/Database/OCI8/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ protected function _limit(string $sql, bool $offsetIgnore = false): string
}

$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' : '');
samsonasik marked this conversation as resolved.
Show resolved Hide resolved

return sprintf($limitTemplateQuery, $sql, $offset + $this->QBLimit + 1, $offset);
}
Expand Down
2 changes: 1 addition & 1 deletion system/HTTP/DownloadResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ private function getContentDisposition(): string

$result = sprintf('attachment; filename="%s"', $downloadFilename);

if ($utf8Filename) {
if ($utf8Filename !== '') {
$result .= '; filename*=UTF-8\'\'' . rawurlencode($utf8Filename);
}

Expand Down
18 changes: 9 additions & 9 deletions system/Helpers/filesystem_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -379,19 +379,19 @@ function symbolic_permissions(int $perms): string
}

// 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;
}
Expand Down
2 changes: 1 addition & 1 deletion system/Helpers/form_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
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 = current_url(true);
} // If an action is not a full URL then turn it into one
elseif (strpos($action, '://') === false) {
Expand Down
2 changes: 1 addition & 1 deletion system/Helpers/html_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ function doctype(string $type = 'html5'): string
function script_tag($src = '', bool $indexPage = false): string
{
$cspNonce = csp_script_nonce();
$cspNonce = $cspNonce ? ' ' . $cspNonce : $cspNonce;
$cspNonce = $cspNonce !== '' ? ' ' . $cspNonce : $cspNonce;
$script = '<script' . $cspNonce . ' ';
if (! is_array($src)) {
$src = ['src' => $src];
Expand Down
2 changes: 1 addition & 1 deletion system/Helpers/url_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ function safe_mailto(string $email, string $title = '', $attributes = ''): strin

// improve obfuscation by eliminating newlines & whitespace
$cspNonce = csp_script_nonce();
$cspNonce = $cspNonce ? ' ' . $cspNonce : $cspNonce;
$cspNonce = $cspNonce !== '' ? ' ' . $cspNonce : $cspNonce;
$output = '<script' . $cspNonce . '>'
. 'var l=new Array();';

Expand Down
2 changes: 1 addition & 1 deletion system/Router/RouteCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -767,7 +767,7 @@ public function group(string $name, ...$params)
// 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 !== '' ? trim($oldGroup . '/' . $name, '/') : $oldGroup;

$callback = array_pop($params);

Expand Down
2 changes: 1 addition & 1 deletion system/Session/Handlers/FileHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public function __construct(SessionConfig $config, string $ipAddress)
} else {
$sessionPath = rtrim(ini_get('session.save_path'), '/\\');

if (! $sessionPath) {
if ($sessionPath === '') {
$sessionPath = WRITEPATH . 'session';
}

Expand Down
2 changes: 1 addition & 1 deletion system/View/Table.php
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ public function generate($tableData = null)

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;

Expand Down
2 changes: 1 addition & 1 deletion tests/system/Cache/ResponseCacheTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ private function createIncomingRequest(
): 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;
Expand Down
Loading