Skip to content

Commit 6bacf2c

Browse files
authored
Merge pull request #4729 from jeromegamez/coalesce
Replace `isset()` with the `??` null coalesce operator
2 parents a0f6c3d + 3ee7705 commit 6bacf2c

11 files changed

Lines changed: 19 additions & 19 deletions

File tree

rector.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
use Rector\EarlyReturn\Rector\If_\ChangeIfElseValueAssignToEarlyReturnRector;
2323
use Rector\EarlyReturn\Rector\If_\RemoveAlwaysElseRector;
2424
use Rector\EarlyReturn\Rector\Return_\PreparedValueToEarlyReturnRector;
25+
use Rector\Php70\Rector\Ternary\TernaryToNullCoalescingRector;
2526
use Rector\Php73\Rector\FuncCall\JsonThrowOnErrorRector;
2627
use Rector\Php73\Rector\FuncCall\StringifyStrNeedlesRector;
2728
use Rector\Set\ValueObject\SetList;
@@ -86,4 +87,5 @@
8687
$services->set(UnnecessaryTernaryExpressionRector::class);
8788
$services->set(RemoveUnusedPrivatePropertyRector::class);
8889
$services->set(RemoveErrorSuppressInTryCatchStmtsRector::class);
90+
$services->set(TernaryToNullCoalescingRector::class);
8991
};

system/CLI/CLI.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -983,7 +983,7 @@ public static function getOption(string $name)
983983

984984
// If the option didn't have a value, simply return TRUE
985985
// so they know it was set, otherwise return the actual value.
986-
$val = static::$options[$name] === null ? true : static::$options[$name];
986+
$val = static::$options[$name] ?? true;
987987

988988
return $val;
989989
}

system/Database/Forge.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -964,8 +964,8 @@ protected function _processFields(bool $createTable = false): array
964964

965965
$field = [
966966
'name' => $key,
967-
'new_name' => isset($attributes['NAME']) ? $attributes['NAME'] : null,
968-
'type' => isset($attributes['TYPE']) ? $attributes['TYPE'] : null,
967+
'new_name' => $attributes['NAME'] ?? null,
968+
'type' => $attributes['TYPE'] ?? null,
969969
'length' => '',
970970
'unsigned' => '',
971971
'null' => '',

system/Database/MySQLi/Result.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ public function getFieldData(): array
9898
$retVal[$i] = new stdClass();
9999
$retVal[$i]->name = $data->name;
100100
$retVal[$i]->type = $data->type;
101-
$retVal[$i]->type_name = in_array($data->type, [1, 247], true) ? 'char' : (isset($dataTypes[$data->type]) ? $dataTypes[$data->type] : null);
101+
$retVal[$i]->type_name = in_array($data->type, [1, 247], true) ? 'char' : ($dataTypes[$data->type] ?? null);
102102
$retVal[$i]->max_length = $data->max_length;
103103
$retVal[$i]->primary_key = (int) ($data->flags & 2);
104104
$retVal[$i]->length = $data->length;

system/Database/SQLSRV/Result.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ public function getFieldData(): array
9999
$retVal[$i] = new stdClass();
100100
$retVal[$i]->name = $field['Name'];
101101
$retVal[$i]->type = $field['Type'];
102-
$retVal[$i]->type_name = isset($dataTypes[$field['Type']]) ? $dataTypes[$field['Type']] : null;
102+
$retVal[$i]->type_name = $dataTypes[$field['Type']] ?? null;
103103
$retVal[$i]->max_length = $field['Size'];
104104
}
105105

system/Database/SQLite3/Result.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public function getFieldData(): array
7676
$retVal[$i]->name = $this->resultID->columnName($i); // @phpstan-ignore-line
7777
$type = $this->resultID->columnType($i); // @phpstan-ignore-line
7878
$retVal[$i]->type = $type;
79-
$retVal[$i]->type_name = isset($dataTypes[$type]) ? $dataTypes[$type] : null;
79+
$retVal[$i]->type_name = $dataTypes[$type] ?? null;
8080
$retVal[$i]->max_length = null;
8181
$retVal[$i]->length = null;
8282
}

system/Database/SQLite3/Table.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -301,12 +301,8 @@ protected function copyData()
301301

302302
foreach ($this->fields as $name => $details)
303303
{
304-
$newFields[] = isset($details['new_name'])
305-
// Are we modifying the column?
306-
? $details['new_name']
307-
: $name;
308-
309-
$exFields[] = $name;
304+
$newFields[] = $details['new_name'] ?? $name;
305+
$exFields[] = $name;
310306
}
311307

312308
$exFields = implode(', ', $exFields);

system/Email/Email.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1432,7 +1432,7 @@ protected function appendAttachments(&$body, $boundary, $multipart = null)
14321432
{
14331433
continue;
14341434
}
1435-
$name = isset($attachment['name'][1]) ? $attachment['name'][1] : basename($attachment['name'][0]);
1435+
$name = $attachment['name'][1] ?? basename($attachment['name'][0]);
14361436
$body .= '--' . $boundary . $this->newline
14371437
. 'Content-Type: ' . $attachment['type'] . '; name="' . $name . '"' . $this->newline
14381438
. 'Content-Disposition: ' . $attachment['disposition'] . ';' . $this->newline

system/HTTP/RequestTrait.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public function getIPAddress(): string
6060
/**
6161
* @deprecated $this->proxyIPs property will be removed in the future
6262
*/
63-
$proxyIPs = isset($this->proxyIPs) ? $this->proxyIPs : config('App')->proxyIPs;
63+
$proxyIPs = $this->proxyIPs ?? config('App')->proxyIPs;
6464
if (! empty($proxyIPs) && ! is_array($proxyIPs))
6565
{
6666
$proxyIPs = explode(',', str_replace(' ', '', $proxyIPs));

system/Session/Session.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,9 @@ public function __construct(SessionHandlerInterface $driver, App $config)
187187
$this->cookieSecure = $config->cookieSecure ?? $this->cookieSecure;
188188
$this->cookieSameSite = $config->cookieSameSite ?? $this->cookieSameSite;
189189

190-
/** @var CookieConfig */
190+
/**
191+
* @var CookieConfig
192+
*/
191193
$cookie = config('Cookie');
192194

193195
$this->cookie = new Cookie($this->sessionCookieName, '', [
@@ -512,7 +514,7 @@ public function set($data, $value = null)
512514
*/
513515
public function get(string $key = null)
514516
{
515-
if (! empty($key) && (! is_null($value = isset($_SESSION[$key]) ? $_SESSION[$key] : null) || ! is_null($value = dot_array_search($key, $_SESSION ?? []))))
517+
if (! empty($key) && (! is_null($value = $_SESSION[$key] ?? null) || ! is_null($value = dot_array_search($key, $_SESSION ?? []))))
516518
{
517519
return $value;
518520
}

0 commit comments

Comments
 (0)