Skip to content

Commit

Permalink
Merge pull request #9244 from samsonasik/refactor-enable-simplify-boo…
Browse files Browse the repository at this point in the history
…l-identical-true

refactor: enable SimplifyBoolIdenticalTrueRector
  • Loading branch information
samsonasik authored Oct 30, 2024
2 parents 8522a37 + 3f8feaa commit caf4d53
Show file tree
Hide file tree
Showing 31 changed files with 69 additions and 72 deletions.
6 changes: 0 additions & 6 deletions phpstan-baseline.php
Original file line number Diff line number Diff line change
Expand Up @@ -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\\.$#',
Expand Down
2 changes: 2 additions & 0 deletions rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -211,6 +212,7 @@
AddMethodCallBasedStrictParamTypeRector::class,
TypedPropertyFromAssignsRector::class,
ClosureReturnTypeRector::class,
SimplifyBoolIdenticalTrueRector::class,
])
->withConfiguredRule(StringClassNameToClassConstantRector::class, [
// keep '\\' prefix string on string '\Foo\Bar'
Expand Down
2 changes: 1 addition & 1 deletion system/CLI/CLI.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions system/Cache/Handlers/FileHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -308,15 +308,15 @@ 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);
}
}
}

closedir($currentDir);

return ($delDir === true && $_level > 0) ? @rmdir($path) : true;
return ($delDir && $_level > 0) ? @rmdir($path) : true;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion system/Config/Services.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
22 changes: 11 additions & 11 deletions system/Database/BaseBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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([]);
}
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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}:";
}

Expand Down Expand Up @@ -1599,7 +1599,7 @@ public function getCompiledSelect(bool $reset = true): string
{
$select = $this->compileSelect();

if ($reset === true) {
if ($reset) {
$this->resetSelect();
}

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -1678,7 +1678,7 @@ public function countAll(bool $reset = true)

$query = $query->getRow();

if ($reset === true) {
if ($reset) {
$this->resetSelect();
}

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -2297,7 +2297,7 @@ public function getCompiledInsert(bool $reset = true)
array_values($this->QBSet)
);

if ($reset === true) {
if ($reset) {
$this->resetWrite();
}

Expand Down Expand Up @@ -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();
}

Expand Down
12 changes: 6 additions & 6 deletions system/Database/BaseConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -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++;
Expand Down Expand Up @@ -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;
}
}
Expand All @@ -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);
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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);
}

Expand Down
14 changes: 7 additions & 7 deletions system/Database/Forge.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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";
Expand Down Expand Up @@ -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";
Expand Down
4 changes: 2 additions & 2 deletions system/Database/MySQLi/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '';
}
Expand Down Expand Up @@ -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) . "%'";
}

Expand Down
2 changes: 1 addition & 1 deletion system/Database/MySQLi/Forge.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'])) . ')';
Expand Down
2 changes: 1 addition & 1 deletion system/Database/OCI8/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
4 changes: 2 additions & 2 deletions system/Database/OCI8/Forge.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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';
Expand Down
2 changes: 1 addition & 1 deletion system/Database/Postgre/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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}:";
}
Expand Down
6 changes: 3 additions & 3 deletions system/Database/Postgre/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
) {
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions system/Database/Postgre/Forge.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'])
Expand Down Expand Up @@ -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';
}

Expand Down
2 changes: 1 addition & 1 deletion system/Database/SQLSRV/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,7 @@ public function countAll(bool $reset = true)

$query = $query->getRow();

if ($reset === true) {
if ($reset) {
$this->resetSelect();
}

Expand Down
2 changes: 1 addition & 1 deletion system/Database/SQLSRV/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Loading

0 comments on commit caf4d53

Please sign in to comment.