Skip to content

Commit

Permalink
Merge pull request #4729 from jeromegamez/coalesce
Browse files Browse the repository at this point in the history
Replace `isset()` with the `??` null coalesce operator
  • Loading branch information
samsonasik authored May 24, 2021
2 parents a0f6c3d + 3ee7705 commit 6bacf2c
Show file tree
Hide file tree
Showing 11 changed files with 19 additions and 19 deletions.
2 changes: 2 additions & 0 deletions rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
use Rector\EarlyReturn\Rector\If_\ChangeIfElseValueAssignToEarlyReturnRector;
use Rector\EarlyReturn\Rector\If_\RemoveAlwaysElseRector;
use Rector\EarlyReturn\Rector\Return_\PreparedValueToEarlyReturnRector;
use Rector\Php70\Rector\Ternary\TernaryToNullCoalescingRector;
use Rector\Php73\Rector\FuncCall\JsonThrowOnErrorRector;
use Rector\Php73\Rector\FuncCall\StringifyStrNeedlesRector;
use Rector\Set\ValueObject\SetList;
Expand Down Expand Up @@ -86,4 +87,5 @@
$services->set(UnnecessaryTernaryExpressionRector::class);
$services->set(RemoveUnusedPrivatePropertyRector::class);
$services->set(RemoveErrorSuppressInTryCatchStmtsRector::class);
$services->set(TernaryToNullCoalescingRector::class);
};
2 changes: 1 addition & 1 deletion system/CLI/CLI.php
Original file line number Diff line number Diff line change
Expand Up @@ -983,7 +983,7 @@ public static function getOption(string $name)

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

return $val;
}
Expand Down
4 changes: 2 additions & 2 deletions system/Database/Forge.php
Original file line number Diff line number Diff line change
Expand Up @@ -964,8 +964,8 @@ protected function _processFields(bool $createTable = false): array

$field = [
'name' => $key,
'new_name' => isset($attributes['NAME']) ? $attributes['NAME'] : null,
'type' => isset($attributes['TYPE']) ? $attributes['TYPE'] : null,
'new_name' => $attributes['NAME'] ?? null,
'type' => $attributes['TYPE'] ?? null,
'length' => '',
'unsigned' => '',
'null' => '',
Expand Down
2 changes: 1 addition & 1 deletion system/Database/MySQLi/Result.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public function getFieldData(): array
$retVal[$i] = new stdClass();
$retVal[$i]->name = $data->name;
$retVal[$i]->type = $data->type;
$retVal[$i]->type_name = in_array($data->type, [1, 247], true) ? 'char' : (isset($dataTypes[$data->type]) ? $dataTypes[$data->type] : null);
$retVal[$i]->type_name = in_array($data->type, [1, 247], true) ? 'char' : ($dataTypes[$data->type] ?? null);
$retVal[$i]->max_length = $data->max_length;
$retVal[$i]->primary_key = (int) ($data->flags & 2);
$retVal[$i]->length = $data->length;
Expand Down
2 changes: 1 addition & 1 deletion system/Database/SQLSRV/Result.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public function getFieldData(): array
$retVal[$i] = new stdClass();
$retVal[$i]->name = $field['Name'];
$retVal[$i]->type = $field['Type'];
$retVal[$i]->type_name = isset($dataTypes[$field['Type']]) ? $dataTypes[$field['Type']] : null;
$retVal[$i]->type_name = $dataTypes[$field['Type']] ?? null;
$retVal[$i]->max_length = $field['Size'];
}

Expand Down
2 changes: 1 addition & 1 deletion system/Database/SQLite3/Result.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public function getFieldData(): array
$retVal[$i]->name = $this->resultID->columnName($i); // @phpstan-ignore-line
$type = $this->resultID->columnType($i); // @phpstan-ignore-line
$retVal[$i]->type = $type;
$retVal[$i]->type_name = isset($dataTypes[$type]) ? $dataTypes[$type] : null;
$retVal[$i]->type_name = $dataTypes[$type] ?? null;
$retVal[$i]->max_length = null;
$retVal[$i]->length = null;
}
Expand Down
8 changes: 2 additions & 6 deletions system/Database/SQLite3/Table.php
Original file line number Diff line number Diff line change
Expand Up @@ -301,12 +301,8 @@ protected function copyData()

foreach ($this->fields as $name => $details)
{
$newFields[] = isset($details['new_name'])
// Are we modifying the column?
? $details['new_name']
: $name;

$exFields[] = $name;
$newFields[] = $details['new_name'] ?? $name;
$exFields[] = $name;
}

$exFields = implode(', ', $exFields);
Expand Down
2 changes: 1 addition & 1 deletion system/Email/Email.php
Original file line number Diff line number Diff line change
Expand Up @@ -1432,7 +1432,7 @@ protected function appendAttachments(&$body, $boundary, $multipart = null)
{
continue;
}
$name = isset($attachment['name'][1]) ? $attachment['name'][1] : basename($attachment['name'][0]);
$name = $attachment['name'][1] ?? basename($attachment['name'][0]);
$body .= '--' . $boundary . $this->newline
. 'Content-Type: ' . $attachment['type'] . '; name="' . $name . '"' . $this->newline
. 'Content-Disposition: ' . $attachment['disposition'] . ';' . $this->newline
Expand Down
2 changes: 1 addition & 1 deletion system/HTTP/RequestTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public function getIPAddress(): string
/**
* @deprecated $this->proxyIPs property will be removed in the future
*/
$proxyIPs = isset($this->proxyIPs) ? $this->proxyIPs : config('App')->proxyIPs;
$proxyIPs = $this->proxyIPs ?? config('App')->proxyIPs;
if (! empty($proxyIPs) && ! is_array($proxyIPs))
{
$proxyIPs = explode(',', str_replace(' ', '', $proxyIPs));
Expand Down
6 changes: 4 additions & 2 deletions system/Session/Session.php
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,9 @@ public function __construct(SessionHandlerInterface $driver, App $config)
$this->cookieSecure = $config->cookieSecure ?? $this->cookieSecure;
$this->cookieSameSite = $config->cookieSameSite ?? $this->cookieSameSite;

/** @var CookieConfig */
/**
* @var CookieConfig
*/
$cookie = config('Cookie');

$this->cookie = new Cookie($this->sessionCookieName, '', [
Expand Down Expand Up @@ -512,7 +514,7 @@ public function set($data, $value = null)
*/
public function get(string $key = null)
{
if (! empty($key) && (! is_null($value = isset($_SESSION[$key]) ? $_SESSION[$key] : null) || ! is_null($value = dot_array_search($key, $_SESSION ?? []))))
if (! empty($key) && (! is_null($value = $_SESSION[$key] ?? null) || ! is_null($value = dot_array_search($key, $_SESSION ?? []))))
{
return $value;
}
Expand Down
6 changes: 3 additions & 3 deletions system/View/Table.php
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ public function generate($tableData = null)
}
}

$out .= $temp . (isset($heading['data']) ? $heading['data'] : '') . $this->template['heading_cell_end'];
$out .= $temp . ($heading['data'] ?? '') . $this->template['heading_cell_end'];
}

$out .= $this->template['heading_row_end'] . $this->newline . $this->template['thead_close'] . $this->newline;
Expand Down Expand Up @@ -352,7 +352,7 @@ public function generate($tableData = null)
}
}

$cell = isset($cell['data']) ? $cell['data'] : '';
$cell = $cell['data'] ?? '';
$out .= $temp;

if ($cell === '' || $cell === null)
Expand Down Expand Up @@ -394,7 +394,7 @@ public function generate($tableData = null)
}
}

$out .= $temp . (isset($footing['data']) ? $footing['data'] : '') . $this->template['footing_cell_end'];
$out .= $temp . ($footing['data'] ?? '') . $this->template['footing_cell_end'];
}

$out .= $this->template['footing_row_end'] . $this->newline . $this->template['tfoot_close'] . $this->newline;
Expand Down

0 comments on commit 6bacf2c

Please sign in to comment.