Skip to content

Commit 04b3c2e

Browse files
committed
chore: apply IfToNullCoalescingAssignRector rule
1 parent 8cf3052 commit 04b3c2e

40 files changed

Lines changed: 100 additions & 226 deletions

system/BaseModel.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1648,9 +1648,7 @@ public function getValidationRules(array $options = []): array
16481648

16491649
protected function ensureValidation(): void
16501650
{
1651-
if ($this->validation === null) {
1652-
$this->validation = service('validation', null, false);
1653-
}
1651+
$this->validation ??= service('validation', null, false);
16541652
}
16551653

16561654
/**

system/CLI/SignalTrait.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,7 @@ protected function isPcntlAvailable(): bool
8181
*/
8282
protected function isPosixAvailable(): bool
8383
{
84-
if (self::$isPosixAvailable === null) {
85-
self::$isPosixAvailable = is_windows() ? false : extension_loaded('posix');
86-
}
84+
self::$isPosixAvailable ??= is_windows() ? false : extension_loaded('posix');
8785

8886
return self::$isPosixAvailable;
8987
}

system/CodeIgniter.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -624,9 +624,7 @@ protected function bootstrapEnvironment()
624624
*/
625625
protected function startBenchmark()
626626
{
627-
if ($this->startTime === null) {
628-
$this->startTime = microtime(true);
629-
}
627+
$this->startTime ??= microtime(true);
630628

631629
$this->benchmark = Services::timer();
632630
$this->benchmark->start('total_execution', $this->startTime);

system/Commands/ListCommands.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,7 @@ protected function listFull(array $commands)
101101
$groups = [];
102102

103103
foreach ($commands as $title => $command) {
104-
if (! isset($groups[$command['group']])) {
105-
$groups[$command['group']] = [];
106-
}
104+
$groups[$command['group']] ??= [];
107105

108106
$groups[$command['group']][$title] = $command;
109107
}

system/Common.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -490,9 +490,7 @@ function esc($data, string $context = 'html', ?string $encoding = null)
490490
static $escapers = [];
491491
$cacheKey = strtolower($encoding ?? 'utf-8');
492492

493-
if (! isset($escapers[$cacheKey])) {
494-
$escapers[$cacheKey] = new Escaper($encoding);
495-
}
493+
$escapers[$cacheKey] ??= new Escaper($encoding);
496494

497495
$data = $escapers[$cacheKey]->{$method}($data);
498496
}
@@ -588,9 +586,7 @@ function function_usable(string $functionName): bool
588586
static $_suhosin_func_blacklist;
589587

590588
if (function_exists($functionName)) {
591-
if (! isset($_suhosin_func_blacklist)) {
592-
$_suhosin_func_blacklist = extension_loaded('suhosin') ? explode(',', trim(ini_get('suhosin.executor.func.blacklist'))) : [];
593-
}
589+
$_suhosin_func_blacklist ??= extension_loaded('suhosin') ? explode(',', trim(ini_get('suhosin.executor.func.blacklist'))) : [];
594590

595591
return ! in_array($functionName, $_suhosin_func_blacklist, true);
596592
}

system/Config/BaseService.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -276,9 +276,7 @@ protected static function getSharedInstance(string $key, ...$params)
276276
public static function autoloader(bool $getShared = true)
277277
{
278278
if ($getShared) {
279-
if (! isset(static::$instances['autoloader'])) {
280-
static::$instances['autoloader'] = new Autoloader();
281-
}
279+
static::$instances['autoloader'] ??= new Autoloader();
282280

283281
return static::$instances['autoloader'];
284282
}

system/Database/BaseBuilder.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1488,9 +1488,7 @@ public function orderBy(string $orderBy, string $direction = '', ?bool $escape =
14881488
$direction = in_array($direction, ['ASC', 'DESC'], true) ? ' ' . $direction : '';
14891489
}
14901490

1491-
if ($escape === null) {
1492-
$escape = $this->db->protectIdentifiers;
1493-
}
1491+
$escape ??= $this->db->protectIdentifiers;
14941492

14951493
if ($escape === false) {
14961494
$qbOrderBy[] = [

system/Database/BaseConnection.php

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -467,9 +467,7 @@ private function getBuiltinPropertyTypesMap(array $properties): array
467467
$className = static::class;
468468
$requested = array_fill_keys($properties, true);
469469

470-
if (! isset(self::$propertyBuiltinTypesCache[$className])) {
471-
self::$propertyBuiltinTypesCache[$className] = [];
472-
}
470+
self::$propertyBuiltinTypesCache[$className] ??= [];
473471

474472
// Fill only the properties requested by this call that are not cached yet.
475473
$missing = array_diff_key($requested, self::$propertyBuiltinTypesCache[$className]);
@@ -1867,10 +1865,7 @@ protected function foreignKeyDataToObjects(array $data)
18671865
foreach ($data as $row) {
18681866
$name = $row['constraint_name'];
18691867

1870-
// for sqlite generate name
1871-
if ($name === null) {
1872-
$name = $row['table_name'] . '_' . implode('_', $row['column_name']) . '_foreign';
1873-
}
1868+
$name ??= $row['table_name'] . '_' . implode('_', $row['column_name']) . '_foreign';
18741869

18751870
$obj = new stdClass();
18761871
$obj->constraint_name = $name;

system/Database/BaseUtils.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -233,9 +233,7 @@ public function getCSVFromResult(ResultInterface $query, string $delim = ',', st
233233
public function getXMLFromResult(ResultInterface $query, array $params = []): string
234234
{
235235
foreach (['root' => 'root', 'element' => 'element', 'newline' => "\n", 'tab' => "\t"] as $key => $val) {
236-
if (! isset($params[$key])) {
237-
$params[$key] = $val;
238-
}
236+
$params[$key] ??= $val;
239237
}
240238

241239
$root = $params['root'];

system/Database/Config.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,7 @@ public static function connect($group = null, bool $getShared = true)
6060
} else {
6161
$dbConfig = config(DbConfig::class);
6262

63-
if ($group === null) {
64-
$group = (ENVIRONMENT === 'testing') ? 'tests' : $dbConfig->defaultGroup;
65-
}
63+
$group ??= (ENVIRONMENT === 'testing') ? 'tests' : $dbConfig->defaultGroup;
6664

6765
assert(is_string($group));
6866

0 commit comments

Comments
 (0)