Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Null Coalesce Operator #861

Merged
merged 1 commit into from
Dec 13, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion system/Database/BaseBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -2411,7 +2411,7 @@ protected function compileSelect($select_override = false)
// is because until the user calls the from() function we don't know if there are aliases
foreach ($this->QBSelect as $key => $val)
{
$no_escape = isset($this->QBNoEscape[$key]) ? $this->QBNoEscape[$key] : null;
$no_escape = $this->QBNoEscape[$key] ?? null;
$this->QBSelect[$key] = $this->db->protectIdentifiers($val, false, $no_escape);
}

Expand Down
4 changes: 2 additions & 2 deletions system/Database/Forge.php
Original file line number Diff line number Diff line change
Expand Up @@ -850,8 +850,8 @@ protected function _processFields($create_table = false)

$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
12 changes: 6 additions & 6 deletions system/Database/MySQLi/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public function connect($persistent = false)
$this->mysqli = mysqli_init();

mysqli_report(MYSQLI_REPORT_ALL & ~MYSQLI_REPORT_INDEX);

$this->mysqli->options(MYSQLI_OPT_CONNECT_TIMEOUT, 10);

if (isset($this->strictOn))
Expand Down Expand Up @@ -169,7 +169,7 @@ public function connect($persistent = false)

$client_flags |= MYSQLI_CLIENT_SSL;
$this->mysqli->ssl_set(
isset($ssl['key']) ? $ssl['key'] : null, isset($ssl['cert']) ? $ssl['cert'] : null, isset($ssl['ca']) ? $ssl['ca'] : null, isset($ssl['capath']) ? $ssl['capath'] : null, isset($ssl['cipher']) ? $ssl['cipher'] : null
$ssl['key'] ?? null, $ssl['cert'] ?? null, $ssl['ca'] ?? null, $ssl['capath'] ?? null, $ssl['cipher'] ?? null
);
}
}
Expand Down Expand Up @@ -486,7 +486,7 @@ public function _indexData(string $table)
}

//--------------------------------------------------------------------

/**
* Returns an object with Foreign key data
*
Expand All @@ -504,16 +504,16 @@ public function _foreignKeyData(string $table)
INNER JOIN information_schema.REFERENTIAL_CONSTRAINTS AS rc
ON tc.CONSTRAINT_NAME = rc.CONSTRAINT_NAME
WHERE
tc.CONSTRAINT_TYPE = '.$this->escape('FOREIGN KEY').' AND
tc.CONSTRAINT_TYPE = '.$this->escape('FOREIGN KEY').' AND
tc.TABLE_SCHEMA = '.$this->escape($this->database).' AND
tc.TABLE_NAME = '.$this->escape($table);

if (($query = $this->query($sql)) === false)
{
return false;
}
$query = $query->getResultObject();

$retval = [];
foreach ($query as $row)
{
Expand Down
16 changes: 8 additions & 8 deletions system/Database/Postgre/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ public function _indexData(string $table)
return false;
}
$query = $query->getResultObject();

$retval = [];
foreach ($query as $row)
{
Expand All @@ -359,7 +359,7 @@ public function _indexData(string $table)
}

//--------------------------------------------------------------------

/**
* Returns an object with Foreign key data
*
Expand All @@ -369,22 +369,22 @@ public function _indexData(string $table)
public function _foreignKeyData(string $table)
{
$sql = 'SELECT
tc.constraint_name, tc.table_name, kcu.column_name,
tc.constraint_name, tc.table_name, kcu.column_name,
ccu.table_name AS foreign_table_name,
ccu.column_name AS foreign_column_name
FROM information_schema.table_constraints AS tc
FROM information_schema.table_constraints AS tc
JOIN information_schema.key_column_usage AS kcu
ON tc.constraint_name = kcu.constraint_name
JOIN information_schema.constraint_column_usage AS ccu
ON ccu.constraint_name = tc.constraint_name
WHERE constraint_type = '.$this->escape('FOREIGN KEY').' AND tc.table_name = '.$this->escape($table);

if (($query = $this->query($sql)) === false)
{
return false;
}
$query = $query->getResultObject();

$retval = [];
foreach ($query as $row)
{
Expand All @@ -400,7 +400,7 @@ public function _foreignKeyData(string $table)
}

//--------------------------------------------------------------------

/**
* Returns the last error code and message.
*
Expand Down Expand Up @@ -429,7 +429,7 @@ public function insertID()
{
$v = pg_version($this->connID);
// 'server' key is only available since PostgreSQL 7.4
$v = isset($v['server']) ? $v['server'] : 0;
$v = $v['server'] ?? 0;

$table = func_num_args() > 0 ? func_get_arg(0) : null;
$column = func_num_args() > 1 ? func_get_arg(1) : null;
Expand Down
2 changes: 1 addition & 1 deletion system/Filters/Filters.php
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ protected function processMethods()
}

// Request method won't be set for CLI-based requests
$method = isset($_SERVER['REQUEST_METHOD']) ? strtolower($_SERVER['REQUEST_METHOD']) : 'cli';
$method = strtolower($_SERVER['REQUEST_METHOD'] ?? 'cli');

if (array_key_exists($method, $this->config->methods))
{
Expand Down
2 changes: 1 addition & 1 deletion system/HTTP/CURLRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,7 @@ protected function setResponseHeaders(array $headers = [])

if (isset($matches[2]))
{
$this->response->setStatusCode($matches[2], isset($matches[3]) ? $matches[3] : null);
$this->response->setStatusCode($matches[2], $matches[3] ?? null);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion system/HTTP/Files/UploadedFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ public function getErrorString()

$error = is_null($this->error) ? UPLOAD_ERR_OK : $this->error;

return isset($errors[$error]) ? sprintf($errors[$error], $this->getName()) : sprintf('The file "%s" was not uploaded due to an unknown error.', $this->getName());
return sprintf($errors[$error] ?? 'The file "%s" was not uploaded due to an unknown error.', $this->getName());
}

//--------------------------------------------------------------------
Expand Down
12 changes: 6 additions & 6 deletions system/HTTP/IncomingRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -594,7 +594,7 @@ public function detectPath($protocol)
break;
case 'PATH_INFO':
default:
$path = isset($_SERVER[$protocol]) ? $_SERVER[$protocol] : $this->parseRequestURI();
$path = $_SERVER[$protocol] ?? $this->parseRequestURI();
break;
}

Expand Down Expand Up @@ -657,8 +657,8 @@ protected function parseRequestURI(): string
// parse_url() returns false if no host is present, but the path or query string
// contains a colon followed by a number
$parts = parse_url('http://dummy' . $_SERVER['REQUEST_URI']);
$query = isset($parts['query']) ? $parts['query'] : '';
$uri = isset($parts['path']) ? $parts['path'] : '';
$query = $parts['query'] ?? '';
$uri = $parts['path'] ?? '';

if (isset($_SERVER['SCRIPT_NAME'][0]))
{
Expand All @@ -678,7 +678,7 @@ protected function parseRequestURI(): string
{
$query = explode('?', $query, 2);
$uri = $query[0];
$_SERVER['QUERY_STRING'] = isset($query[1]) ? $query[1] : '';
$_SERVER['QUERY_STRING'] = $query[1] ?? '';
}
else
{
Expand Down Expand Up @@ -706,7 +706,7 @@ protected function parseRequestURI(): string
*/
protected function parseQueryString(): string
{
$uri = isset($_SERVER['QUERY_STRING']) ? $_SERVER['QUERY_STRING'] : @getenv('QUERY_STRING');
$uri = $_SERVER['QUERY_STRING'] ?? @getenv('QUERY_STRING');

if (trim($uri, '/') === '')
{
Expand All @@ -715,7 +715,7 @@ protected function parseQueryString(): string
elseif (strncmp($uri, '/', 1) === 0)
{
$uri = explode('?', $uri, 2);
$_SERVER['QUERY_STRING'] = isset($uri[1]) ? $uri[1] : '';
$_SERVER['QUERY_STRING'] = $uri[1] ?? '';
$uri = $uri[0];
}

Expand Down
4 changes: 2 additions & 2 deletions system/HTTP/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ public function appendBody($data)
*/
public function populateHeaders()
{
$contentType = isset($_SERVER['CONTENT_TYPE']) ? $_SERVER['CONTENT_TYPE'] : getenv('CONTENT_TYPE');
$contentType = $_SERVER['CONTENT_TYPE'] ?? getenv('CONTENT_TYPE');
if ( ! empty($contentType))
{
$this->setHeader('Content-Type', $contentType);
Expand Down Expand Up @@ -403,7 +403,7 @@ protected function getHeaderName($name): string
{
$lower_name = strtolower($name);

return isset($this->headerMap[$lower_name]) ? $this->headerMap[$lower_name] : $name;
return $this->headerMap[$lower_name] ?? $name;
}

//--------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion system/Helpers/html_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ function doctype($type = 'html5'): string
$customDocTypesNs = "Config\{$env}\DocTypes";
$doctypes = $customDocTypesNs::$list;
}
return isset($doctypes[$type]) ? $doctypes[$type] : false;
return $doctypes[$type] ?? false;
}

}
Expand Down
27 changes: 13 additions & 14 deletions system/Helpers/number_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,7 @@ function format_number($num, int $precision = 1, string $locale = null, array $o
$locale = $locale ?? \CodeIgniter\Config\Services::request()->getLocale();

// Type can be any of the NumberFormatter options, but provide a default.
$type = isset($options['type']) ? (int) $options['type'] :
NumberFormatter::DECIMAL;
$type = (int) ($options['type'] ?? NumberFormatter::DECIMAL);

// In order to specify a precision, we'll have to modify
// the pattern used by NumberFormatter.
Expand Down Expand Up @@ -247,7 +246,7 @@ function format_number($num, int $precision = 1, string $locale = null, array $o
{
/**
* Convert a number to a roman numeral.
*
*
* @param int $num it will convert to int
*
* @return string
Expand All @@ -267,22 +266,22 @@ function number_to_roman($num)
switch ($th)
{
case 1:
$key1 = 'I';
$key2 = 'V';
$key_f = 'X';
$key1 = 'I';
$key2 = 'V';
$key_f = 'X';
break;
case 2:
$key1 = 'X';
$key2 = 'L';
$key_f = 'C';
$key1 = 'X';
$key2 = 'L';
$key_f = 'C';
break;
case 3:
$key1 = 'C';
$key2 = 'D';
$key_f = 'M';
$key1 = 'C';
$key2 = 'D';
$key_f = 'M';
break;
case 4:
$key1 = 'M';
$key1 = 'M';
break;
}
$n = $num % 10;
Expand Down Expand Up @@ -322,4 +321,4 @@ function number_to_roman($num)
};
return $_number_to_roman($num, 1);
}
}
}
2 changes: 1 addition & 1 deletion system/Helpers/url_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ function anchor_popup($uri = '', $title = '', $attributes = false, \Config\App $

foreach (['width' => '800', 'height' => '600', 'scrollbars' => 'yes', 'menubar' => 'no', 'status' => 'yes', 'resizable' => 'yes', 'screenx' => '0', 'screeny' => '0'] as $key => $val)
{
$atts[$key] = isset($attributes[$key]) ? $attributes[$key] : $val;
$atts[$key] = $attributes[$key] ?? $val;
unset($attributes[$key]);
}

Expand Down
2 changes: 1 addition & 1 deletion system/Images/Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ public function getProperties($return = false)

$vals = getimagesize($path);
$types = [1 => 'gif', 2 => 'jpeg', 3 => 'png'];
$mime = (isset($types[$vals[2]])) ? 'image/' . $types[$vals[2]] : 'image/jpg';
$mime = 'image/' . ($types[$vals[2]] ?? 'jpg');

if ($return === true)
{
Expand Down
2 changes: 1 addition & 1 deletion system/Language/Language.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public function getLine(string $line, array $args = [])
// Will load the language file and strings.
list($file, $line) = $this->parseLine($line);

$output = isset($this->language[$file][$line]) ? $this->language[$file][$line] : $line;
$output = $this->language[$file][$line] ?? $line;

if (! empty($args))
{
Expand Down
5 changes: 2 additions & 3 deletions system/Router/RouteCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ class RouteCollection implements RouteCollectionInterface
public function __construct(FileLocator $locator)
{
// Get HTTP verb
$this->HTTPVerb = isset($_SERVER['REQUEST_METHOD']) ? strtolower($_SERVER['REQUEST_METHOD']) : 'cli';
$this->HTTPVerb = strtolower($_SERVER['REQUEST_METHOD'] ?? 'cli');

$this->fileLocator = $locator;
}
Expand Down Expand Up @@ -771,8 +771,7 @@ public function resource(string $name, array $options = null): RouteCollectionIn

// In order to allow customization of allowed id values
// we need someplace to store them.
$id = isset($this->placeholders[$this->defaultPlaceholder]) ? $this->placeholders[$this->defaultPlaceholder] :
'(:segment)';
$id = $this->placeholders[$this->defaultPlaceholder] ?? '(:segment)';

if (isset($options['placeholder']))
{
Expand Down
2 changes: 1 addition & 1 deletion system/Session/Handlers/MemcachedHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ public function open($save_path, $name)
continue;
}

if ( ! $this->memcached->addServer($match[1], $match[2], isset($match[3]) ? $match[3] : 0))
if ( ! $this->memcached->addServer($match[1], $match[2], $match[3] ?? 0))
{
$this->logger->error('Could not add ' . $match[1] . ':' . $match[2] . ' to Memcached server pool.');
}
Expand Down
2 changes: 1 addition & 1 deletion system/Session/Session.php
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,7 @@ public function get(string $key = null)
{
if (isset($key))
{
return isset($_SESSION[$key]) ? $_SESSION[$key] : null;
return $_SESSION[$key] ?? null;
}
elseif (empty($_SESSION))
{
Expand Down