From dede747236f61d73f6c0c0fac7cf575fb610b184 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Wed, 30 Oct 2024 16:34:36 +0700 Subject: [PATCH 1/2] refactor: enable SimplifyBoolIdenticalTrueRector --- phpstan-baseline.php | 6 ----- rector.php | 2 ++ system/CLI/CLI.php | 2 +- system/Cache/Handlers/FileHandler.php | 4 ++-- system/Config/Services.php | 2 +- system/Database/BaseBuilder.php | 22 +++++++++---------- system/Database/BaseConnection.php | 12 +++++----- system/Database/Forge.php | 14 ++++++------ system/Database/MySQLi/Connection.php | 4 ++-- system/Database/MySQLi/Forge.php | 2 +- system/Database/OCI8/Connection.php | 2 +- system/Database/OCI8/Forge.php | 4 ++-- system/Database/Postgre/Builder.php | 2 +- system/Database/Postgre/Connection.php | 6 ++--- system/Database/Postgre/Forge.php | 4 ++-- system/Database/SQLSRV/Builder.php | 2 +- system/Database/SQLSRV/Connection.php | 2 +- system/Database/SQLSRV/Forge.php | 2 +- system/Database/SQLite3/Connection.php | 4 ++-- system/HTTP/DownloadResponse.php | 2 +- system/Helpers/form_helper.php | 6 ++--- system/Helpers/html_helper.php | 14 ++++++------ system/Helpers/url_helper.php | 2 +- system/Helpers/xml_helper.php | 4 ++-- system/Images/Handlers/ImageMagickHandler.php | 2 +- system/Images/Image.php | 2 +- system/Log/Handlers/FileHandler.php | 3 ++- system/Pager/Pager.php | 2 +- system/Router/AutoRouter.php | 2 +- system/Typography/Typography.php | 2 +- system/Validation/Validation.php | 2 +- 31 files changed, 69 insertions(+), 72 deletions(-) diff --git a/phpstan-baseline.php b/phpstan-baseline.php index ea228647c992..2e6e8b31ec37 100644 --- a/phpstan-baseline.php +++ b/phpstan-baseline.php @@ -7849,12 +7849,6 @@ 'count' => 1, 'path' => __DIR__ . '/system/Log/Handlers/FileHandler.php', ]; -$ignoreErrors[] = [ - // identifier: identical.alwaysTrue - 'message' => '#^Strict comparison using \\=\\=\\= between true and true will always evaluate to true\\.$#', - 'count' => 1, - 'path' => __DIR__ . '/system/Log/Handlers/FileHandler.php', -]; $ignoreErrors[] = [ // identifier: missingType.iterableValue 'message' => '#^Method CodeIgniter\\\\Log\\\\Logger\\:\\:determineFile\\(\\) return type has no value type specified in iterable type array\\.$#', diff --git a/rector.php b/rector.php index 913dc7277e41..89647759b914 100644 --- a/rector.php +++ b/rector.php @@ -19,6 +19,7 @@ use Rector\CodeQuality\Rector\FuncCall\ChangeArrayPushToArrayAssignRector; use Rector\CodeQuality\Rector\FuncCall\SingleInArrayToCompareRector; use Rector\CodeQuality\Rector\FunctionLike\SimplifyUselessVariableRector; +use Rector\CodeQuality\Rector\Identical\SimplifyBoolIdenticalTrueRector; use Rector\CodeQuality\Rector\If_\CombineIfRector; use Rector\CodeQuality\Rector\If_\ExplicitBoolCompareRector; use Rector\CodeQuality\Rector\If_\ShortenElseIfRector; @@ -211,6 +212,7 @@ AddMethodCallBasedStrictParamTypeRector::class, TypedPropertyFromAssignsRector::class, ClosureReturnTypeRector::class, + SimplifyBoolIdenticalTrueRector::class, ]) ->withConfiguredRule(StringClassNameToClassConstantRector::class, [ // keep '\\' prefix string on string '\Foo\Bar' diff --git a/system/CLI/CLI.php b/system/CLI/CLI.php index bfe1511eed02..54ca6a5ca97e 100644 --- a/system/CLI/CLI.php +++ b/system/CLI/CLI.php @@ -514,7 +514,7 @@ public static function beep(int $num = 1) */ public static function wait(int $seconds, bool $countdown = false) { - if ($countdown === true) { + if ($countdown) { $time = $seconds; while ($time > 0) { diff --git a/system/Cache/Handlers/FileHandler.php b/system/Cache/Handlers/FileHandler.php index cf45a6544e27..a86a45e83d00 100644 --- a/system/Cache/Handlers/FileHandler.php +++ b/system/Cache/Handlers/FileHandler.php @@ -308,7 +308,7 @@ protected function deleteFiles(string $path, bool $delDir = false, bool $htdocs if ($filename !== '.' && $filename !== '..') { if (is_dir($path . DIRECTORY_SEPARATOR . $filename) && $filename[0] !== '.') { $this->deleteFiles($path . DIRECTORY_SEPARATOR . $filename, $delDir, $htdocs, $_level + 1); - } elseif ($htdocs !== true || ! preg_match('/^(\.htaccess|index\.(html|htm|php)|web\.config)$/i', $filename)) { + } elseif (! $htdocs || ! preg_match('/^(\.htaccess|index\.(html|htm|php)|web\.config)$/i', $filename)) { @unlink($path . DIRECTORY_SEPARATOR . $filename); } } @@ -316,7 +316,7 @@ protected function deleteFiles(string $path, bool $delDir = false, bool $htdocs closedir($currentDir); - return ($delDir === true && $_level > 0) ? @rmdir($path) : true; + return ($delDir && $_level > 0) ? @rmdir($path) : true; } /** diff --git a/system/Config/Services.php b/system/Config/Services.php index 1a8843fa39b4..28e521df3f0e 100644 --- a/system/Config/Services.php +++ b/system/Config/Services.php @@ -202,7 +202,7 @@ public static function csp(?CSPConfig $config = null, bool $getShared = true) */ public static function curlrequest(array $options = [], ?ResponseInterface $response = null, ?App $config = null, bool $getShared = true) { - if ($getShared === true) { + if ($getShared) { return static::getSharedInstance('curlrequest', $options, $response, $config); } diff --git a/system/Database/BaseBuilder.php b/system/Database/BaseBuilder.php index 9d5a02db9f6e..570340dffb9b 100644 --- a/system/Database/BaseBuilder.php +++ b/system/Database/BaseBuilder.php @@ -579,7 +579,7 @@ public function distinct(bool $val = true) */ public function from($from, bool $overwrite = false): self { - if ($overwrite === true) { + if ($overwrite) { $this->QBFrom = []; $this->db->setAliasedTables([]); } @@ -769,7 +769,7 @@ protected function whereHaving(string $qbKey, $key, $value = null, string $type foreach ($keyValue as $k => $v) { $prefix = empty($this->{$qbKey}) ? $this->groupGetType('') : $this->groupGetType($type); - if ($rawSqlOnly === true) { + if ($rawSqlOnly) { $k = ''; $op = ''; } elseif ($v !== null) { @@ -1150,7 +1150,7 @@ protected function _like($field, string $match = '', string $type = 'AND ', stri $keyValue = ! is_array($field) ? [$field => $match] : $field; foreach ($keyValue as $k => $v) { - if ($insensitiveSearch === true) { + if ($insensitiveSearch) { $v = strtolower($v); } @@ -1187,7 +1187,7 @@ protected function _like($field, string $match = '', string $type = 'AND ', stri */ protected function _like_statement(?string $prefix, string $column, ?string $not, string $bind, bool $insensitiveSearch = false): string { - if ($insensitiveSearch === true) { + if ($insensitiveSearch) { return "{$prefix} LOWER(" . $this->db->escapeIdentifiers($column) . ") {$not} LIKE :{$bind}:"; } @@ -1599,7 +1599,7 @@ public function getCompiledSelect(bool $reset = true): string { $select = $this->compileSelect(); - if ($reset === true) { + if ($reset) { $this->resetSelect(); } @@ -1643,7 +1643,7 @@ public function get(?int $limit = null, int $offset = 0, bool $reset = true) ? $this->getCompiledSelect($reset) : $this->db->query($this->compileSelect(), $this->binds, false); - if ($reset === true) { + if ($reset) { $this->resetSelect(); // Clear our binds so we don't eat up memory @@ -1678,7 +1678,7 @@ public function countAll(bool $reset = true) $query = $query->getRow(); - if ($reset === true) { + if ($reset) { $this->resetSelect(); } @@ -1727,7 +1727,7 @@ public function countAllResults(bool $reset = true) $result = $this->db->query($sql, $this->binds, false); - if ($reset === true) { + if ($reset) { $this->resetSelect(); } elseif (! isset($this->QBOrderBy)) { $this->QBOrderBy = $orderBy; @@ -1781,7 +1781,7 @@ public function getWhere($where = null, ?int $limit = null, ?int $offset = 0, bo ? $this->getCompiledSelect($reset) : $this->db->query($this->compileSelect(), $this->binds, false); - if ($reset === true) { + if ($reset) { $this->resetSelect(); // Clear our binds so we don't eat up memory @@ -2297,7 +2297,7 @@ public function getCompiledInsert(bool $reset = true) array_values($this->QBSet) ); - if ($reset === true) { + if ($reset) { $this->resetWrite(); } @@ -2466,7 +2466,7 @@ public function getCompiledUpdate(bool $reset = true) $sql = $this->_update($this->QBFrom[0], $this->QBSet); - if ($reset === true) { + if ($reset) { $this->resetWrite(); } diff --git a/system/Database/BaseConnection.php b/system/Database/BaseConnection.php index 56340c8decd5..487f01df4ccb 100644 --- a/system/Database/BaseConnection.php +++ b/system/Database/BaseConnection.php @@ -848,7 +848,7 @@ public function transBegin(bool $testMode = false): bool // Reset the transaction failure flag. // If the $test_mode flag is set to TRUE transactions will be rolled back // even if the queries produce a successful result. - $this->transFailure = ($testMode === true); + $this->transFailure = ($testMode); if ($this->_transBegin()) { $this->transDepth++; @@ -1124,7 +1124,7 @@ public function protectIdentifiers($item, bool $prefixSingle = false, ?bool $pro $item = preg_replace('/^' . $this->swapPre . '(\S+?)/', $this->DBPrefix . '\\1', $item); } // Do we prefix an item with no segments? - elseif ($prefixSingle === true && ! str_starts_with($item, $this->DBPrefix)) { + elseif ($prefixSingle && ! str_starts_with($item, $this->DBPrefix)) { $item = $this->DBPrefix . $item; } } @@ -1147,7 +1147,7 @@ private function protectDotItem(string $item, string $alias, bool $protectIdenti // NOTE: The ! empty() condition prevents this method // from breaking when QB isn't enabled. if (! empty($this->aliasedTables) && in_array($parts[0], $this->aliasedTables, true)) { - if ($protectIdentifiers === true) { + if ($protectIdentifiers) { foreach ($parts as $key => $val) { if (! in_array($val, $this->reservedIdentifiers, true)) { $parts[$key] = $this->escapeIdentifiers($val); @@ -1198,7 +1198,7 @@ private function protectDotItem(string $item, string $alias, bool $protectIdenti $item = implode('.', $parts); } - if ($protectIdentifiers === true) { + if ($protectIdentifiers) { $item = $this->escapeIdentifiers($item); } @@ -1372,7 +1372,7 @@ public function escapeString($str, bool $like = false) $str = $this->_escapeString($str); // escape LIKE condition wildcards - if ($like === true) { + if ($like) { return str_replace( [ $this->likeEscapeChar, @@ -1501,7 +1501,7 @@ public function listTables(bool $constrainByPrefix = false) */ public function tableExists(string $tableName, bool $cached = true): bool { - if ($cached === true) { + if ($cached) { return in_array($this->protectIdentifiers($tableName, true, false, false), $this->listTables(), true); } diff --git a/system/Database/Forge.php b/system/Database/Forge.php index 595cd6156b5f..735303614b51 100644 --- a/system/Database/Forge.php +++ b/system/Database/Forge.php @@ -449,12 +449,12 @@ public function addForeignKey( */ public function dropKey(string $table, string $keyName, bool $prefixKeyName = true): bool { - $keyName = $this->db->escapeIdentifiers(($prefixKeyName === true ? $this->db->DBPrefix : '') . $keyName); + $keyName = $this->db->escapeIdentifiers(($prefixKeyName ? $this->db->DBPrefix : '') . $keyName); $table = $this->db->escapeIdentifiers($this->db->DBPrefix . $table); $dropKeyAsConstraint = $this->dropKeyAsConstraint($table, $keyName); - if ($dropKeyAsConstraint === true) { + if ($dropKeyAsConstraint) { $sql = sprintf( $this->dropConstraintStr, $table, @@ -559,7 +559,7 @@ public function createTable(string $table, bool $ifNotExists = false, array $att } // If table exists lets stop here - if ($ifNotExists === true && $this->db->tableExists($table, false)) { + if ($ifNotExists && $this->db->tableExists($table, false)) { $this->reset(); return true; @@ -895,7 +895,7 @@ protected function _processFields(bool $createTable = false): array $attributes = array_change_key_case($attributes, CASE_UPPER); - if ($createTable === true && empty($attributes['TYPE'])) { + if ($createTable && empty($attributes['TYPE'])) { continue; } @@ -942,7 +942,7 @@ protected function _processFields(bool $createTable = false): array } else { $field['null'] = ' NOT ' . $this->null; } - } elseif ($createTable === true) { + } elseif ($createTable) { $field['null'] = ' NOT ' . $this->null; } @@ -1085,7 +1085,7 @@ protected function _processPrimaryKeys(string $table, bool $asQuery = false): st } if (isset($this->primaryKeys['fields']) && $this->primaryKeys['fields'] !== []) { - if ($asQuery === true) { + if ($asQuery) { $sql .= 'ALTER TABLE ' . $this->db->escapeIdentifiers($this->db->DBPrefix . $table) . ' ADD '; } else { $sql .= ",\n\t"; @@ -1229,7 +1229,7 @@ protected function _processForeignKeys(string $table, bool $asQuery = false): ar $referenceTableFilled = $this->db->escapeIdentifiers($this->db->DBPrefix . $fkey['referenceTable']); $referenceFieldFilled = implode(', ', $this->db->escapeIdentifiers($fkey['referenceField'])); - if ($asQuery === true) { + if ($asQuery) { $sqls[$index] .= 'ALTER TABLE ' . $this->db->escapeIdentifiers($this->db->DBPrefix . $table) . ' ADD '; } else { $sqls[$index] .= ",\n\t"; diff --git a/system/Database/MySQLi/Connection.php b/system/Database/MySQLi/Connection.php index 068dfba5b9e9..6524d95b41f1 100644 --- a/system/Database/MySQLi/Connection.php +++ b/system/Database/MySQLi/Connection.php @@ -96,7 +96,7 @@ public function connect(bool $persistent = false) $port = null; $socket = $this->hostname; } else { - $hostname = ($persistent === true) ? 'p:' . $this->hostname : $this->hostname; + $hostname = ($persistent) ? 'p:' . $this->hostname : $this->hostname; $port = empty($this->port) ? null : $this->port; $socket = ''; } @@ -399,7 +399,7 @@ protected function _listTables(bool $prefixLimit = false, ?string $tableName = n return $sql . ' LIKE ' . $this->escape($tableName); } - if ($prefixLimit !== false && $this->DBPrefix !== '') { + if ($prefixLimit && $this->DBPrefix !== '') { return $sql . " LIKE '" . $this->escapeLikeStringDirect($this->DBPrefix) . "%'"; } diff --git a/system/Database/MySQLi/Forge.php b/system/Database/MySQLi/Forge.php index 132bde1258cc..3bde0c518daf 100644 --- a/system/Database/MySQLi/Forge.php +++ b/system/Database/MySQLi/Forge.php @@ -222,7 +222,7 @@ protected function _processIndexes(string $table, bool $asQuery = false): array implode('_', $this->keys[$i]['fields']) : $this->keys[$i]['keyName']); - if ($asQuery === true) { + if ($asQuery) { $sqls[$index] = 'ALTER TABLE ' . $this->db->escapeIdentifiers($table) . " ADD {$unique}KEY " . $keyName . ' (' . implode(', ', $this->db->escapeIdentifiers($this->keys[$i]['fields'])) . ')'; diff --git a/system/Database/OCI8/Connection.php b/system/Database/OCI8/Connection.php index 2b870b755b44..c59d588ccec1 100644 --- a/system/Database/OCI8/Connection.php +++ b/system/Database/OCI8/Connection.php @@ -274,7 +274,7 @@ protected function _listTables(bool $prefixLimit = false, ?string $tableName = n return $sql . ' WHERE "TABLE_NAME" LIKE ' . $this->escape($tableName); } - if ($prefixLimit !== false && $this->DBPrefix !== '') { + if ($prefixLimit && $this->DBPrefix !== '') { return $sql . ' WHERE "TABLE_NAME" LIKE \'' . $this->escapeLikeString($this->DBPrefix) . "%' " . sprintf($this->likeEscapeStr, $this->likeEscapeChar); } diff --git a/system/Database/OCI8/Forge.php b/system/Database/OCI8/Forge.php index 5a10363be769..7d81cff8b506 100644 --- a/system/Database/OCI8/Forge.php +++ b/system/Database/OCI8/Forge.php @@ -135,7 +135,7 @@ protected function _alterTable(string $alterType, string $table, $processedField $wantToAddNull = ! str_contains($processedFields[$i]['null'], ' NOT'); $currentNullable = $nullableMap[$processedFields[$i]['name']]; - if ($wantToAddNull === true && $currentNullable === true) { + if ($wantToAddNull && $currentNullable === true) { $processedFields[$i]['null'] = ''; } elseif ($processedFields[$i]['null'] === '' && $currentNullable === false) { // Nullable by default @@ -293,7 +293,7 @@ protected function _dropTable(string $table, bool $ifExists, bool $cascade) { $sql = parent::_dropTable($table, $ifExists, $cascade); - if ($sql !== true && $cascade === true) { + if ($sql !== true && $cascade) { $sql .= ' CASCADE CONSTRAINTS PURGE'; } elseif ($sql !== true) { $sql .= ' PURGE'; diff --git a/system/Database/Postgre/Builder.php b/system/Database/Postgre/Builder.php index 12845a0e4f54..faae0eda8a9b 100644 --- a/system/Database/Postgre/Builder.php +++ b/system/Database/Postgre/Builder.php @@ -293,7 +293,7 @@ protected function _truncate(string $table): string */ protected function _like_statement(?string $prefix, string $column, ?string $not, string $bind, bool $insensitiveSearch = false): string { - $op = $insensitiveSearch === true ? 'ILIKE' : 'LIKE'; + $op = $insensitiveSearch ? 'ILIKE' : 'LIKE'; return "{$prefix} {$column} {$not} {$op} :{$bind}:"; } diff --git a/system/Database/Postgre/Connection.php b/system/Database/Postgre/Connection.php index ec886dbd4d8b..416d6e02f86f 100644 --- a/system/Database/Postgre/Connection.php +++ b/system/Database/Postgre/Connection.php @@ -74,11 +74,11 @@ public function connect(bool $persistent = false) $this->convertDSN(); } - $this->connID = $persistent === true ? pg_pconnect($this->DSN) : pg_connect($this->DSN); + $this->connID = $persistent ? pg_pconnect($this->DSN) : pg_connect($this->DSN); if ($this->connID !== false) { if ( - $persistent === true + $persistent && pg_connection_status($this->connID) === PGSQL_CONNECTION_BAD && pg_ping($this->connID) === false ) { @@ -289,7 +289,7 @@ protected function _listTables(bool $prefixLimit = false, ?string $tableName = n return $sql . ' AND "table_name" LIKE ' . $this->escape($tableName); } - if ($prefixLimit !== false && $this->DBPrefix !== '') { + if ($prefixLimit && $this->DBPrefix !== '') { return $sql . ' AND "table_name" LIKE \'' . $this->escapeLikeString($this->DBPrefix) . "%' " . sprintf($this->likeEscapeStr, $this->likeEscapeChar); diff --git a/system/Database/Postgre/Forge.php b/system/Database/Postgre/Forge.php index 7a61bed5a57c..b516172737ae 100644 --- a/system/Database/Postgre/Forge.php +++ b/system/Database/Postgre/Forge.php @@ -118,7 +118,7 @@ protected function _alterTable(string $alterType, string $table, $processedField $nullable = false; } $sqls[] = $sql . ' ALTER COLUMN ' . $this->db->escapeIdentifiers($field['name']) - . ($nullable === true ? ' DROP' : ' SET') . ' NOT NULL'; + . ($nullable ? ' DROP' : ' SET') . ' NOT NULL'; if (! empty($field['new_name'])) { $sqls[] = $sql . ' RENAME COLUMN ' . $this->db->escapeIdentifiers($field['name']) @@ -195,7 +195,7 @@ protected function _dropTable(string $table, bool $ifExists, bool $cascade): str { $sql = parent::_dropTable($table, $ifExists, $cascade); - if ($cascade === true) { + if ($cascade) { $sql .= ' CASCADE'; } diff --git a/system/Database/SQLSRV/Builder.php b/system/Database/SQLSRV/Builder.php index fcc0b170084f..c1272cdcf326 100644 --- a/system/Database/SQLSRV/Builder.php +++ b/system/Database/SQLSRV/Builder.php @@ -518,7 +518,7 @@ public function countAll(bool $reset = true) $query = $query->getRow(); - if ($reset === true) { + if ($reset) { $this->resetSelect(); } diff --git a/system/Database/SQLSRV/Connection.php b/system/Database/SQLSRV/Connection.php index 7e008e27c451..7d60ad1cabd1 100644 --- a/system/Database/SQLSRV/Connection.php +++ b/system/Database/SQLSRV/Connection.php @@ -215,7 +215,7 @@ protected function _listTables(bool $prefixLimit = false, ?string $tableName = n return $sql .= ' AND [TABLE_NAME] LIKE ' . $this->escape($tableName); } - if ($prefixLimit === true && $this->DBPrefix !== '') { + if ($prefixLimit && $this->DBPrefix !== '') { $sql .= " AND [TABLE_NAME] LIKE '" . $this->escapeLikeString($this->DBPrefix) . "%' " . sprintf($this->likeEscapeStr, $this->likeEscapeChar); } diff --git a/system/Database/SQLSRV/Forge.php b/system/Database/SQLSRV/Forge.php index cae4eda2a4f5..3bfda3bfe895 100644 --- a/system/Database/SQLSRV/Forge.php +++ b/system/Database/SQLSRV/Forge.php @@ -263,7 +263,7 @@ protected function _alterTable(string $alterType, string $table, $processedField $nullable = false; } $sqls[] = $sql . ' ALTER COLUMN ' . $this->db->escapeIdentifiers($field['name']) - . " {$field['type']}{$field['length']} " . ($nullable === true ? '' : 'NOT') . ' NULL'; + . " {$field['type']}{$field['length']} " . ($nullable ? '' : 'NOT') . ' NULL'; if (! empty($field['comment'])) { $sqls[] = 'EXEC sys.sp_addextendedproperty ' diff --git a/system/Database/SQLite3/Connection.php b/system/Database/SQLite3/Connection.php index 9945d41de11b..a1a03eff61f5 100644 --- a/system/Database/SQLite3/Connection.php +++ b/system/Database/SQLite3/Connection.php @@ -202,7 +202,7 @@ protected function _listTables(bool $prefixLimit = false, ?string $tableName = n return 'SELECT "NAME" FROM "SQLITE_MASTER" WHERE "TYPE" = \'table\'' . ' AND "NAME" NOT LIKE \'sqlite!_%\' ESCAPE \'!\'' - . (($prefixLimit !== false && $this->DBPrefix !== '') + . (($prefixLimit && $this->DBPrefix !== '') ? ' AND "NAME" LIKE \'' . $this->escapeLikeString($this->DBPrefix) . '%\' ' . sprintf($this->likeEscapeStr, $this->likeEscapeChar) : ''); } @@ -359,7 +359,7 @@ protected function _indexData(string $table): array */ protected function _foreignKeyData(string $table): array { - if ($this->supportsForeignKeys() !== true) { + if (! $this->supportsForeignKeys()) { return []; } diff --git a/system/HTTP/DownloadResponse.php b/system/HTTP/DownloadResponse.php index 6b293fbca239..56953823693d 100644 --- a/system/HTTP/DownloadResponse.php +++ b/system/HTTP/DownloadResponse.php @@ -142,7 +142,7 @@ private function setContentTypeByMimeType(): void $mime = null; $charset = ''; - if ($this->setMime === true && ($lastDotPosition = strrpos($this->filename, '.')) !== false) { + if ($this->setMime && ($lastDotPosition = strrpos($this->filename, '.')) !== false) { $mime = Mimes::guessTypeFromExtension(substr($this->filename, $lastDotPosition + 1)); $charset = $this->charset; } diff --git a/system/Helpers/form_helper.php b/system/Helpers/form_helper.php index 2e5b9f7ca576..422c5f1adbb2 100644 --- a/system/Helpers/form_helper.php +++ b/system/Helpers/form_helper.php @@ -582,7 +582,7 @@ function set_select(string $field, string $value = '', bool $default = false): s } if ($input === null) { - return ($default === true) ? ' selected="selected"' : ''; + return ($default) ? ' selected="selected"' : ''; } if (is_array($input)) { @@ -636,7 +636,7 @@ function set_checkbox(string $field, string $value = '', bool $default = false): return ($input === $value) ? ' checked="checked"' : ''; } - return ($default === true) ? ' checked="checked"' : ''; + return ($default) ? ' checked="checked"' : ''; } } @@ -673,7 +673,7 @@ function set_radio(string $field, string $value = '', bool $default = false): st return ((string) $input === $value) ? ' checked="checked"' : ''; } - return ($default === true) ? ' checked="checked"' : ''; + return ($default) ? ' checked="checked"' : ''; } } diff --git a/system/Helpers/html_helper.php b/system/Helpers/html_helper.php index b9e5e5c8ed0e..30733acd5175 100644 --- a/system/Helpers/html_helper.php +++ b/system/Helpers/html_helper.php @@ -113,7 +113,7 @@ function img($src = '', bool $indexPage = false, $attributes = ''): string // Check for a relative URI if (! preg_match('#^([a-z]+:)?//#i', $src['src']) && ! str_starts_with($src['src'], 'data:')) { - if ($indexPage === true) { + if ($indexPage) { $img .= ' src="' . site_url($src['src']) . '"'; } else { $img .= ' src="' . slash_item('baseURL') . $src['src'] . '"'; @@ -207,7 +207,7 @@ function script_tag($src = '', bool $indexPage = false): string foreach ($src as $k => $v) { if ($k === 'src' && ! preg_match('#^([a-z]+:)?//#i', $v)) { - if ($indexPage === true) { + if ($indexPage) { $script .= 'src="' . site_url($v) . '" '; } else { $script .= 'src="' . slash_item('baseURL') . $v . '" '; @@ -302,7 +302,7 @@ function video($src, string $unsupportedMessage = '', string $attributes = '', a if (_has_protocol($src)) { $video .= ' src="' . $src . '"'; - } elseif ($indexPage === true) { + } elseif ($indexPage) { $video .= ' src="' . site_url($src) . '"'; } else { $video .= ' src="' . slash_item('baseURL') . $src . '"'; @@ -349,7 +349,7 @@ function audio($src, string $unsupportedMessage = '', string $attributes = '', a if (_has_protocol($src)) { $audio .= ' src="' . $src . '"'; - } elseif ($indexPage === true) { + } elseif ($indexPage) { $audio .= ' src="' . site_url($src) . '"'; } else { $audio .= ' src="' . slash_item('baseURL') . $src . '"'; @@ -422,7 +422,7 @@ function _media(string $name, array $types = [], string $unsupportedMessage = '' function source(string $src, string $type = 'unknown', string $attributes = '', bool $indexPage = false): string { if (! _has_protocol($src)) { - $src = $indexPage === true ? site_url($src) : slash_item('baseURL') . $src; + $src = $indexPage ? site_url($src) : slash_item('baseURL') . $src; } $source = 'width ?? 0) . 'x' . ($this->height ?? 0) . "{$escape}! \"" . $source . '" "' . $destination . '"'; diff --git a/system/Images/Image.php b/system/Images/Image.php index a2cf51436121..ec6d4b8fa5c0 100644 --- a/system/Images/Image.php +++ b/system/Images/Image.php @@ -116,7 +116,7 @@ public function getProperties(bool $return = false) $mime = 'image/' . ($types[$vals[2]] ?? 'jpg'); - if ($return === true) { + if ($return) { return [ 'width' => $vals[0], 'height' => $vals[1], diff --git a/system/Log/Handlers/FileHandler.php b/system/Log/Handlers/FileHandler.php index 42dd9ceefc0f..64d1485f0f7a 100644 --- a/system/Log/Handlers/FileHandler.php +++ b/system/Log/Handlers/FileHandler.php @@ -76,6 +76,7 @@ public function handle($level, $message): bool $msg = ''; + $newfile = false; if (! is_file($filepath)) { $newfile = true; @@ -117,7 +118,7 @@ public function handle($level, $message): bool flock($fp, LOCK_UN); fclose($fp); - if (isset($newfile) && $newfile === true) { + if ($newfile) { chmod($filepath, $this->filePermissions); } diff --git a/system/Pager/Pager.php b/system/Pager/Pager.php index af0e9accfaee..e5fbb9df5b34 100644 --- a/system/Pager/Pager.php +++ b/system/Pager/Pager.php @@ -288,7 +288,7 @@ public function getPageURI(?int $page = null, string $group = 'default', bool $r $uri->setQueryArray($query); } - return ($returnObject === true) + return ($returnObject) ? $uri : URI::createURIString( $uri->getScheme(), diff --git a/system/Router/AutoRouter.php b/system/Router/AutoRouter.php index 6e9f3248c86e..bb47bf96c89a 100644 --- a/system/Router/AutoRouter.php +++ b/system/Router/AutoRouter.php @@ -260,7 +260,7 @@ public function setDirectory(?string $dir = null, bool $append = false, bool $va } } - if ($append !== true || ($this->directory === null || $this->directory === '')) { + if (! $append || ($this->directory === null || $this->directory === '')) { $this->directory = trim($dir, '/') . '/'; } else { $this->directory .= trim($dir, '/') . '/'; diff --git a/system/Typography/Typography.php b/system/Typography/Typography.php index 89687d72e2d1..c8ca5131171c 100644 --- a/system/Typography/Typography.php +++ b/system/Typography/Typography.php @@ -214,7 +214,7 @@ public function autoTypography(string $str, bool $reduceLinebreaks = false): str ]; // Do we need to reduce empty lines? - if ($reduceLinebreaks === true) { + if ($reduceLinebreaks) { $table['#

\n*

#'] = ''; } else { // If we have empty paragraph tags we add a non-breaking space diff --git a/system/Validation/Validation.php b/system/Validation/Validation.php index a4d817d2a9b4..66ed1f8e48a3 100644 --- a/system/Validation/Validation.php +++ b/system/Validation/Validation.php @@ -456,7 +456,7 @@ private function processPermitEmpty($value, array $rules, array $data) } } - if ($passed === true) { + if ($passed) { return true; } } From 3f8feaa5893e30509fa21edafbdcdb478f3fabd0 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Wed, 30 Oct 2024 16:41:24 +0700 Subject: [PATCH 2/2] refactor: clean up parentheses on assign and ternary --- system/Database/BaseConnection.php | 2 +- system/Database/MySQLi/Connection.php | 2 +- system/Helpers/form_helper.php | 6 +++--- system/Pager/Pager.php | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/system/Database/BaseConnection.php b/system/Database/BaseConnection.php index 487f01df4ccb..65bf6fcdbdac 100644 --- a/system/Database/BaseConnection.php +++ b/system/Database/BaseConnection.php @@ -848,7 +848,7 @@ public function transBegin(bool $testMode = false): bool // Reset the transaction failure flag. // If the $test_mode flag is set to TRUE transactions will be rolled back // even if the queries produce a successful result. - $this->transFailure = ($testMode); + $this->transFailure = $testMode; if ($this->_transBegin()) { $this->transDepth++; diff --git a/system/Database/MySQLi/Connection.php b/system/Database/MySQLi/Connection.php index 6524d95b41f1..b1095003e286 100644 --- a/system/Database/MySQLi/Connection.php +++ b/system/Database/MySQLi/Connection.php @@ -96,7 +96,7 @@ public function connect(bool $persistent = false) $port = null; $socket = $this->hostname; } else { - $hostname = ($persistent) ? 'p:' . $this->hostname : $this->hostname; + $hostname = $persistent ? 'p:' . $this->hostname : $this->hostname; $port = empty($this->port) ? null : $this->port; $socket = ''; } diff --git a/system/Helpers/form_helper.php b/system/Helpers/form_helper.php index 422c5f1adbb2..58cd828e3faa 100644 --- a/system/Helpers/form_helper.php +++ b/system/Helpers/form_helper.php @@ -582,7 +582,7 @@ function set_select(string $field, string $value = '', bool $default = false): s } if ($input === null) { - return ($default) ? ' selected="selected"' : ''; + return $default ? ' selected="selected"' : ''; } if (is_array($input)) { @@ -636,7 +636,7 @@ function set_checkbox(string $field, string $value = '', bool $default = false): return ($input === $value) ? ' checked="checked"' : ''; } - return ($default) ? ' checked="checked"' : ''; + return $default ? ' checked="checked"' : ''; } } @@ -673,7 +673,7 @@ function set_radio(string $field, string $value = '', bool $default = false): st return ((string) $input === $value) ? ' checked="checked"' : ''; } - return ($default) ? ' checked="checked"' : ''; + return $default ? ' checked="checked"' : ''; } } diff --git a/system/Pager/Pager.php b/system/Pager/Pager.php index e5fbb9df5b34..3bdc85388c18 100644 --- a/system/Pager/Pager.php +++ b/system/Pager/Pager.php @@ -288,7 +288,7 @@ public function getPageURI(?int $page = null, string $group = 'default', bool $r $uri->setQueryArray($query); } - return ($returnObject) + return $returnObject ? $uri : URI::createURIString( $uri->getScheme(),