diff --git a/rector.php b/rector.php index b5c0cc63b29b..50248202373a 100644 --- a/rector.php +++ b/rector.php @@ -13,10 +13,9 @@ use Rector\Caching\ValueObject\Storage\FileCacheStorage; use Rector\CodeQuality\Rector\Empty_\SimplifyEmptyCheckOnEmptyArrayRector; -use Rector\CodeQuality\Rector\Expression\InlineIfToExplicitIfRector; -use Rector\CodeQuality\Rector\Foreach_\UnusedForeachValueToArrayKeysRector; use Rector\CodeQuality\Rector\FuncCall\CompactToVariablesRector; use Rector\CodeQuality\Rector\FunctionLike\SimplifyUselessVariableRector; +use Rector\CodeQuality\Rector\Isset_\IssetOnPropertyObjectToPropertyExistsRector; use Rector\CodeQuality\Rector\Ternary\TernaryEmptyArrayArrayDimFetchToCoalesceRector; use Rector\CodingStyle\Rector\ClassMethod\FuncGetArgsToVariadicParamRector; use Rector\CodingStyle\Rector\ClassMethod\MakeInheritedMethodVisibilitySameAsParentRector; @@ -167,6 +166,9 @@ CompactToVariablesRector::class, RemoveDataProviderParamKeysRector::class, + + // possibly isset() on purpose, on updated Config classes property accross versions + IssetOnPropertyObjectToPropertyExistsRector::class, ]) // auto import fully qualified class names ->withImportNames(removeUnusedImports: true) @@ -179,9 +181,7 @@ CountArrayToEmptyArrayComparisonRector::class, ChangeNestedForeachIfsToEarlyContinueRector::class, ChangeIfElseValueAssignToEarlyReturnRector::class, - InlineIfToExplicitIfRector::class, PreparedValueToEarlyReturnRector::class, - UnusedForeachValueToArrayKeysRector::class, RemoveErrorSuppressInTryCatchStmtsRector::class, FuncGetArgsToVariadicParamRector::class, MakeInheritedMethodVisibilitySameAsParentRector::class, @@ -202,4 +202,4 @@ // keep '\\' prefix string on string '\Foo\Bar' StringClassNameToClassConstantRector::SHOULD_KEEP_PRE_SLASH => true, ]) - ->withCodeQualityLevel(41); + ->withCodeQualityLevel(51); diff --git a/system/Commands/Database/CreateDatabase.php b/system/Commands/Database/CreateDatabase.php index 0c8d2016dc93..facd060abf6e 100644 --- a/system/Commands/Database/CreateDatabase.php +++ b/system/Commands/Database/CreateDatabase.php @@ -109,7 +109,7 @@ public function run(array $params) $config->{$group}['database'] = $name; if ($name !== ':memory:') { - $dbName = ! str_contains($name, DIRECTORY_SEPARATOR) ? WRITEPATH . $name : $name; + $dbName = str_contains($name, DIRECTORY_SEPARATOR) ? $name : WRITEPATH . $name; if (is_file($dbName)) { CLI::error("Database \"{$dbName}\" already exists.", 'light_gray', 'red'); diff --git a/system/Database/BaseBuilder.php b/system/Database/BaseBuilder.php index eb2dc6f73bd2..a2988dcede5a 100644 --- a/system/Database/BaseBuilder.php +++ b/system/Database/BaseBuilder.php @@ -1152,7 +1152,7 @@ protected function _like($field, string $match = '', string $type = 'AND ', stri return $this; } - $keyValue = ! is_array($field) ? [$field => $match] : $field; + $keyValue = is_array($field) ? $field : [$field => $match]; foreach ($keyValue as $k => $v) { if ($insensitiveSearch) { @@ -3065,7 +3065,7 @@ protected function compileSelect($selectOverride = false): string if ($selectOverride !== false) { $sql = $selectOverride; } else { - $sql = (! $this->QBDistinct) ? 'SELECT ' : 'SELECT DISTINCT '; + $sql = $this->QBDistinct ? 'SELECT DISTINCT ' : 'SELECT '; if (empty($this->QBSelect)) { $sql .= '*'; diff --git a/system/Database/BaseUtils.php b/system/Database/BaseUtils.php index 26957ffe01f1..a9310e1d4e32 100644 --- a/system/Database/BaseUtils.php +++ b/system/Database/BaseUtils.php @@ -250,7 +250,7 @@ public function getXMLFromResult(ResultInterface $query, array $params = []): st $xml .= $tab . '<' . $element . '>' . $newline; foreach ($row as $key => $val) { - $val = (! empty($val)) ? xml_convert((string) $val) : ''; + $val = empty($val) ? '' : xml_convert((string) $val); $xml .= $tab . $tab . '<' . $key . '>' . $val . '' . $newline; } diff --git a/system/Database/Database.php b/system/Database/Database.php index 80e902d5ab58..36a22862cdd4 100644 --- a/system/Database/Database.php +++ b/system/Database/Database.php @@ -136,9 +136,9 @@ protected function parseDSN(array $params): array */ protected function initDriver(string $driver, string $class, $argument): object { - $classname = (! str_contains($driver, '\\')) - ? "CodeIgniter\\Database\\{$driver}\\{$class}" - : $driver . '\\' . $class; + $classname = str_contains($driver, '\\') + ? $driver . '\\' . $class + : "CodeIgniter\\Database\\{$driver}\\{$class}"; return new $classname($argument); } diff --git a/system/Database/MigrationRunner.php b/system/Database/MigrationRunner.php index fdff86589132..8f723924539f 100644 --- a/system/Database/MigrationRunner.php +++ b/system/Database/MigrationRunner.php @@ -659,7 +659,7 @@ public function getHistory(string $group = 'default'): array $query = $builder->orderBy('id', 'ASC')->get(); - return ! empty($query) ? $query->getResultObject() : []; + return empty($query) ? [] : $query->getResultObject(); } /** @@ -676,7 +676,7 @@ public function getBatchHistory(int $batch, $order = 'asc'): array ->orderBy('id', $order) ->get(); - return ! empty($query) ? $query->getResultObject() : []; + return empty($query) ? [] : $query->getResultObject(); } /** diff --git a/system/Database/SQLSRV/Builder.php b/system/Database/SQLSRV/Builder.php index ec4d41195626..0b17a52ff344 100644 --- a/system/Database/SQLSRV/Builder.php +++ b/system/Database/SQLSRV/Builder.php @@ -584,7 +584,7 @@ protected function compileSelect($selectOverride = false): string if ($selectOverride !== false) { $sql = $selectOverride; } else { - $sql = (! $this->QBDistinct) ? 'SELECT ' : 'SELECT DISTINCT '; + $sql = $this->QBDistinct ? 'SELECT DISTINCT ' : 'SELECT '; // SQL Server can't work with select * if group by is specified if (empty($this->QBSelect) && $this->QBGroupBy !== [] && is_array($this->QBGroupBy)) { diff --git a/system/Debug/Timer.php b/system/Debug/Timer.php index 37e9901977e7..98b1299a89f7 100644 --- a/system/Debug/Timer.php +++ b/system/Debug/Timer.php @@ -46,7 +46,7 @@ class Timer public function start(string $name, ?float $time = null) { $this->timers[strtolower($name)] = [ - 'start' => ! empty($time) ? $time : microtime(true), + 'start' => empty($time) ? microtime(true) : $time, 'end' => null, ]; diff --git a/system/Email/Email.php b/system/Email/Email.php index 9ed8465daa66..19282e7e5cce 100644 --- a/system/Email/Email.php +++ b/system/Email/Email.php @@ -839,7 +839,7 @@ public function setNewline($newline = "\n") */ public function setCRLF($CRLF = "\n") { - $this->CRLF = ! in_array($CRLF, ["\n", "\r\n", "\r"], true) ? "\n" : $CRLF; + $this->CRLF = in_array($CRLF, ["\n", "\r\n", "\r"], true) ? $CRLF : "\n"; return $this; } @@ -2222,7 +2222,7 @@ protected function mimeTypes($ext = '') { $mime = Mimes::guessTypeFromExtension(strtolower($ext)); - return ! empty($mime) ? $mime : 'application/x-unknown-content-type'; + return empty($mime) ? 'application/x-unknown-content-type' : $mime; } public function __destruct() diff --git a/system/HTTP/Response.php b/system/HTTP/Response.php index 9de285b85d08..3c59f2e9800d 100644 --- a/system/HTTP/Response.php +++ b/system/HTTP/Response.php @@ -221,7 +221,7 @@ public function getStatusCode(): int public function getReasonPhrase() { if ($this->reason === '') { - return ! empty($this->statusCode) ? static::$statusCodes[$this->statusCode] : ''; + return empty($this->statusCode) ? '' : static::$statusCodes[$this->statusCode]; } return $this->reason; diff --git a/system/HTTP/URI.php b/system/HTTP/URI.php index 5bcf11de655a..6045f0fd3e64 100644 --- a/system/HTTP/URI.php +++ b/system/HTTP/URI.php @@ -181,9 +181,9 @@ public static function createURIString( } if ((string) $path !== '') { - $uri .= ! str_ends_with($uri, '/') - ? '/' . ltrim($path, '/') - : ltrim($path, '/'); + $uri .= str_ends_with($uri, '/') + ? ltrim($path, '/') + : '/' . ltrim($path, '/'); } if ((string) $query !== '') { diff --git a/system/Helpers/form_helper.php b/system/Helpers/form_helper.php index 7b89bb9ec173..a9415821f970 100644 --- a/system/Helpers/form_helper.php +++ b/system/Helpers/form_helper.php @@ -350,7 +350,7 @@ function form_checkbox($data = '', string $value = '', bool $checked = false, $e { $defaults = [ 'type' => 'checkbox', - 'name' => (! is_array($data) ? $data : ''), + 'name' => is_array($data) ? '' : $data, 'value' => $value, ]; diff --git a/system/Images/Handlers/ImageMagickHandler.php b/system/Images/Handlers/ImageMagickHandler.php index bd2df0e49478..58bb0c912b94 100644 --- a/system/Images/Handlers/ImageMagickHandler.php +++ b/system/Images/Handlers/ImageMagickHandler.php @@ -72,7 +72,7 @@ public function __construct($config = null) */ public function _resize(bool $maintainRatio = false) { - $source = ! empty($this->resource) ? $this->resource : $this->image()->getPathname(); + $source = empty($this->resource) ? $this->image()->getPathname() : $this->resource; $destination = $this->getResourcePath(); $escape = '\\'; @@ -99,7 +99,7 @@ public function _resize(bool $maintainRatio = false) */ public function _crop() { - $source = ! empty($this->resource) ? $this->resource : $this->image()->getPathname(); + $source = empty($this->resource) ? $this->image()->getPathname() : $this->resource; $destination = $this->getResourcePath(); $extent = ' '; @@ -126,7 +126,7 @@ protected function _rotate(int $angle) { $angle = '-rotate ' . $angle; - $source = ! empty($this->resource) ? $this->resource : $this->image()->getPathname(); + $source = empty($this->resource) ? $this->image()->getPathname() : $this->resource; $destination = $this->getResourcePath(); $action = ' ' . $angle . ' ' . escapeshellarg($source) . ' ' . escapeshellarg($destination); @@ -147,7 +147,7 @@ protected function _flatten(int $red = 255, int $green = 255, int $blue = 255) { $flatten = "-background 'rgb({$red},{$green},{$blue})' -flatten"; - $source = ! empty($this->resource) ? $this->resource : $this->image()->getPathname(); + $source = empty($this->resource) ? $this->image()->getPathname() : $this->resource; $destination = $this->getResourcePath(); $action = ' ' . $flatten . ' ' . escapeshellarg($source) . ' ' . escapeshellarg($destination); @@ -168,7 +168,7 @@ protected function _flip(string $direction) { $angle = $direction === 'horizontal' ? '-flop' : '-flip'; - $source = ! empty($this->resource) ? $this->resource : $this->image()->getPathname(); + $source = empty($this->resource) ? $this->image()->getPathname() : $this->resource; $destination = $this->getResourcePath(); $action = ' ' . $angle . ' ' . escapeshellarg($source) . ' ' . escapeshellarg($destination); @@ -411,7 +411,7 @@ protected function _text(string $text, array $options = []) // Text $cmd .= ' -annotate 0 ' . escapeshellarg($text); - $source = ! empty($this->resource) ? $this->resource : $this->image()->getPathname(); + $source = empty($this->resource) ? $this->image()->getPathname() : $this->resource; $destination = $this->getResourcePath(); $cmd = ' ' . escapeshellarg($source) . ' ' . $cmd . ' ' . escapeshellarg($destination); diff --git a/system/Model.php b/system/Model.php index 44ed52a0edd0..60759b9e201f 100644 --- a/system/Model.php +++ b/system/Model.php @@ -396,7 +396,7 @@ protected function doInsert(array $row) // If insertion succeeded then save the insert ID if ($result) { - $this->insertID = ! $this->useAutoIncrement ? $row[$this->primaryKey] : $this->db->insertID(); + $this->insertID = $this->useAutoIncrement ? $this->db->insertID() : $row[$this->primaryKey]; } return $result; diff --git a/system/Test/Fabricator.php b/system/Test/Fabricator.php index 1a7c5c8f392f..b366464d5a26 100644 --- a/system/Test/Fabricator.php +++ b/system/Test/Fabricator.php @@ -168,7 +168,7 @@ public static function resetCounts() */ public static function getCount(string $table): int { - return ! isset(self::$tableCounts[$table]) ? 0 : self::$tableCounts[$table]; + return self::$tableCounts[$table] ?? 0; } /** diff --git a/system/Validation/Validation.php b/system/Validation/Validation.php index d3f2a3dc828f..37cf552499d9 100644 --- a/system/Validation/Validation.php +++ b/system/Validation/Validation.php @@ -918,7 +918,7 @@ protected function getErrorMessage( $args = [ 'field' => ($label === null || $label === '') ? $field : lang($label), - 'param' => (! isset($this->rules[$param]['label'])) ? $param : lang($this->rules[$param]['label']), + 'param' => isset($this->rules[$param]['label']) ? lang($this->rules[$param]['label']) : $param, 'value' => $value ?? '', ];