Skip to content

Commit

Permalink
Use null coalescing operator
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Babker committed Sep 28, 2017
1 parent ef4ce3c commit 2dff49d
Show file tree
Hide file tree
Showing 37 changed files with 97 additions and 99 deletions.
10 changes: 5 additions & 5 deletions libraries/src/Cache/CacheStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,11 @@ public function __construct($options = array())
$config = \JFactory::getConfig();

$this->_hash = md5($config->get('secret'));
$this->_application = (isset($options['application'])) ? $options['application'] : null;
$this->_language = (isset($options['language'])) ? $options['language'] : 'en-GB';
$this->_locking = (isset($options['locking'])) ? $options['locking'] : true;
$this->_lifetime = (isset($options['lifetime'])) ? $options['lifetime'] * 60 : $config->get('cachetime') * 60;
$this->_now = (isset($options['now'])) ? $options['now'] : time();
$this->_application = $options['application'] ?? null;
$this->_language = $options['language'] ?? 'en-GB';
$this->_locking = $options['locking'] ?? true;
$this->_lifetime = ($options['lifetime'] ?? $config->get('cachetime')) * 60;
$this->_now = $options['now'] ?? time();

// Set time threshold value. If the lifetime is not set, default to 60 (0 is BAD)
// _threshold is now available ONLY as a legacy (it's deprecated). It's no longer used in the core.
Expand Down
8 changes: 4 additions & 4 deletions libraries/src/Cache/Controller/CallbackController.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public function get($callback, $args = array(), $id = false, $wrkarounds = false
{
echo Cache::getWorkarounds(
$data['output'],
array('mergehead' => isset($woptions['mergehead']) ? $woptions['mergehead'] : 0)
array('mergehead' => $woptions['mergehead'] ?? 0)
);
}
else
Expand Down Expand Up @@ -113,9 +113,9 @@ public function get($callback, $args = array(), $id = false, $wrkarounds = false
$coptions['modulemode'] = 0;
}

$coptions['nopathway'] = isset($woptions['nopathway']) ? $woptions['nopathway'] : 1;
$coptions['nohead'] = isset($woptions['nohead']) ? $woptions['nohead'] : 1;
$coptions['nomodules'] = isset($woptions['nomodules']) ? $woptions['nomodules'] : 1;
$coptions['nopathway'] = $woptions['nopathway'] ?? 1;
$coptions['nohead'] = $woptions['nohead'] ?? 1;
$coptions['nomodules'] = $woptions['nomodules'] ?? 1;

ob_start();
ob_implicit_flush(false);
Expand Down
2 changes: 1 addition & 1 deletion libraries/src/Cache/Controller/PageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public function get($id = false, $group = 'page')

if ($etag == $id)
{
$browserCache = isset($this->options['browsercache']) ? $this->options['browsercache'] : false;
$browserCache = $this->options['browsercache'] ?? false;

if ($browserCache)
{
Expand Down
8 changes: 4 additions & 4 deletions libraries/src/Categories/Categories.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,11 @@ public function __construct($options)
$this->_table = $options['table'];
$this->_field = isset($options['field']) && $options['field'] ? $options['field'] : 'catid';
$this->_key = isset($options['key']) && $options['key'] ? $options['key'] : 'id';
$this->_statefield = isset($options['statefield']) ? $options['statefield'] : 'state';
$this->_statefield = $options['statefield'] ?? 'state';

$options['access'] = isset($options['access']) ? $options['access'] : 'true';
$options['published'] = isset($options['published']) ? $options['published'] : 1;
$options['countItems'] = isset($options['countItems']) ? $options['countItems'] : 0;
$options['access'] = $options['access'] ?? 'true';
$options['published'] = $options['published'] ?? 1;
$options['countItems'] = $options['countItems'] ?? 0;
$options['currentlang'] = Multilanguage::isEnabled() ? Factory::getLanguage()->getTag() : 0;

$this->_options = $options;
Expand Down
4 changes: 2 additions & 2 deletions libraries/src/Document/Document.php
Original file line number Diff line number Diff line change
Expand Up @@ -560,7 +560,7 @@ public function addScriptVersion($url, $options = array(), $attribs = array())
$attribs = array();

// Old version parameter.
$options['version'] = isset($argList[1]) && !is_null($argList[1]) ? $argList[1] : 'auto';
$options['version'] = $argList[1] ?? 'auto';

// Old mime type parameter.
if (!empty($argList[2]))
Expand Down Expand Up @@ -751,7 +751,7 @@ public function addStyleSheetVersion($url, $options = array(), $attribs = array(
$attribs = array();

// Old version parameter.
$options['version'] = isset($argList[1]) && !is_null($argList[1]) ? $argList[1] : 'auto';
$options['version'] = $argList[1] ?? 'auto';

// Old mime type parameter.
if (!empty($argList[2]))
Expand Down
4 changes: 2 additions & 2 deletions libraries/src/Document/ErrorDocument.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ public function render($cache = false, $params = array())
$file = 'error.php';

// Check template
$directory = isset($params['directory']) ? $params['directory'] : 'templates';
$directory = $params['directory'] ?? 'templates';
$template = isset($params['template']) ? \JFilterInput::getInstance()->clean($params['template'], 'cmd') : 'system';

if (!file_exists($directory . '/' . $template . '/' . $file))
Expand All @@ -157,7 +157,7 @@ public function render($cache = false, $params = array())
// Set variables
$this->baseurl = Uri::base(true);
$this->template = $template;
$this->debug = isset($params['debug']) ? $params['debug'] : false;
$this->debug = $params['debug'] ?? false;
$this->error = $this->_error;

// Load the language file for the template if able
Expand Down
32 changes: 16 additions & 16 deletions libraries/src/Document/HtmlDocument.php
Original file line number Diff line number Diff line change
Expand Up @@ -237,16 +237,16 @@ public function setHeadData($data)
return;
}

$this->title = (isset($data['title']) && !empty($data['title'])) ? $data['title'] : $this->title;
$this->description = (isset($data['description']) && !empty($data['description'])) ? $data['description'] : $this->description;
$this->link = (isset($data['link']) && !empty($data['link'])) ? $data['link'] : $this->link;
$this->_metaTags = (isset($data['metaTags']) && !empty($data['metaTags'])) ? $data['metaTags'] : $this->_metaTags;
$this->_links = (isset($data['links']) && !empty($data['links'])) ? $data['links'] : $this->_links;
$this->_styleSheets = (isset($data['styleSheets']) && !empty($data['styleSheets'])) ? $data['styleSheets'] : $this->_styleSheets;
$this->_style = (isset($data['style']) && !empty($data['style'])) ? $data['style'] : $this->_style;
$this->_scripts = (isset($data['scripts']) && !empty($data['scripts'])) ? $data['scripts'] : $this->_scripts;
$this->_script = (isset($data['script']) && !empty($data['script'])) ? $data['script'] : $this->_script;
$this->_custom = (isset($data['custom']) && !empty($data['custom'])) ? $data['custom'] : $this->_custom;
$this->title = $data['title'] ?? $this->title;
$this->description = $data['description'] ?? $this->description;
$this->link = $data['link'] ?? $this->link;
$this->_metaTags = $data['metaTags'] ?? $this->_metaTags;
$this->_links = $data['links'] ?? $this->_links;
$this->_styleSheets = $data['styleSheets'] ?? $this->_styleSheets;
$this->_style = $data['style'] ?? $this->_style;
$this->_scripts = $data['scripts'] ?? $this->_scripts;
$this->_script = $data['script'] ?? $this->_script;
$this->_custom = $data['custom'] ?? $this->_custom;

if (isset($data['scriptText']) && !empty($data['scriptText']))
{
Expand Down Expand Up @@ -448,7 +448,7 @@ public function getBuffer($type = null, $name = null, $attribs = array())
return parent::$_buffer;
}

$title = (isset($attribs['title'])) ? $attribs['title'] : null;
$title = $attribs['title'] ?? null;

if (isset(parent::$_buffer[$type][$name][$title]))
{
Expand Down Expand Up @@ -510,8 +510,8 @@ public function setBuffer($content, $options = array())
$args = func_get_args();
$options = array();
$options['type'] = $args[1];
$options['name'] = (isset($args[2])) ? $args[2] : null;
$options['title'] = (isset($args[3])) ? $args[3] : null;
$options['name'] = $args[2] ?? null;
$options['title'] = $args[3] ?? null;
}

parent::$_buffer[$options['type']][$options['name']][$options['title']] = $content;
Expand Down Expand Up @@ -687,7 +687,7 @@ protected function _loadTemplate($directory, $filename)
protected function _fetchTemplate($params = array())
{
// Check
$directory = isset($params['directory']) ? $params['directory'] : 'templates';
$directory = $params['directory'] ?? 'templates';
$filter = \JFilterInput::getInstance();
$template = $filter->clean($params['template'], 'cmd');
$file = $filter->clean($params['file'], 'cmd');
Expand All @@ -712,7 +712,7 @@ protected function _fetchTemplate($params = array())
// Assign the variables
$this->template = $template;
$this->baseurl = Uri::base(true);
$this->params = isset($params['params']) ? $params['params'] : new Registry;
$this->params = $params['params'] ?? new Registry;

// Load
$this->_template = $this->_loadTemplate($directory . '/' . $template, $file);
Expand Down Expand Up @@ -741,7 +741,7 @@ protected function _parseTemplate()
{
$type = $matches[1][$i];
$attribs = empty($matches[2][$i]) ? array() : \JUtility::parseAttributes($matches[2][$i]);
$name = isset($attribs['name']) ? $attribs['name'] : null;
$name = $attribs['name'] ?? null;

// Separate buffers to be executed first and last
if ($type == 'module' || $type == 'modules')
Expand Down
2 changes: 1 addition & 1 deletion libraries/src/Document/Renderer/Html/ModuleRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function render($module, $attribs = array(), $content = null)
{
if (!is_object($module))
{
$title = isset($attribs['title']) ? $attribs['title'] : null;
$title = $attribs['title'] ?? null;

$module = ModuleHelper::getModule($module, $title);

Expand Down
2 changes: 1 addition & 1 deletion libraries/src/Feed/Feed.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class Feed implements \ArrayAccess, \Countable
*/
public function __get($name)
{
return isset($this->properties[$name]) ? $this->properties[$name] : null;
return $this->properties[$name] ?? null;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion libraries/src/Feed/FeedEntry.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class FeedEntry
*/
public function __get($name)
{
return (isset($this->properties[$name])) ? $this->properties[$name] : null;
return $this->properties[$name] ?? null;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion libraries/src/Form/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public function __construct($name, array $options = array())
$this->data = new Registry;

// Set the options if specified.
$this->options['control'] = isset($options['control']) ? $options['control'] : false;
$this->options['control'] = $options['control'] ?? false;
}

/**
Expand Down
56 changes: 28 additions & 28 deletions libraries/src/HTML/HTMLHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -696,18 +696,18 @@ public static function stylesheet($file, $options = array(), $attribs = array())
$options = array();

// Old parameters.
$attribs = isset($argList[1]) ? $argList[1] : array();
$options['relative'] = isset($argList[2]) ? $argList[2] : false;
$options['pathOnly'] = isset($argList[3]) ? $argList[3] : false;
$options['detectBrowser'] = isset($argList[4]) ? $argList[4] : true;
$options['detectDebug'] = isset($argList[5]) ? $argList[5] : true;
$attribs = $argList[1] ?? array();
$options['relative'] = $argList[2] ?? false;
$options['pathOnly'] = $argList[3] ?? false;
$options['detectBrowser'] = $argList[4] ?? true;
$options['detectDebug'] = $argList[5] ?? true;
}
else
{
$options['relative'] = isset($options['relative']) ? $options['relative'] : false;
$options['pathOnly'] = isset($options['pathOnly']) ? $options['pathOnly'] : false;
$options['detectBrowser'] = isset($options['detectBrowser']) ? $options['detectBrowser'] : true;
$options['detectDebug'] = isset($options['detectDebug']) ? $options['detectDebug'] : true;
$options['relative'] = $options['relative'] ?? false;
$options['pathOnly'] = $options['pathOnly'] ?? false;
$options['detectBrowser'] = $options['detectBrowser'] ?? true;
$options['detectDebug'] = $options['detectDebug'] ?? true;
}

$includes = static::includeRelativeFiles('css', $file, $options['relative'], $options['detectBrowser'], $options['detectDebug']);
Expand Down Expand Up @@ -769,19 +769,19 @@ public static function script($file, $options = array(), $attribs = array())
$attribs = array();

// Old parameters.
$options['framework'] = isset($argList[1]) ? $argList[1] : false;
$options['relative'] = isset($argList[2]) ? $argList[2] : false;
$options['pathOnly'] = isset($argList[3]) ? $argList[3] : false;
$options['detectBrowser'] = isset($argList[4]) ? $argList[4] : true;
$options['detectDebug'] = isset($argList[5]) ? $argList[5] : true;
$options['framework'] = $argList[1] ?? false;
$options['relative'] = $argList[2] ?? false;
$options['pathOnly'] = $argList[3] ?? false;
$options['detectBrowser'] = $argList[4] ?? true;
$options['detectDebug'] = $argList[5] ?? true;
}
else
{
$options['framework'] = isset($options['framework']) ? $options['framework'] : false;
$options['relative'] = isset($options['relative']) ? $options['relative'] : false;
$options['pathOnly'] = isset($options['pathOnly']) ? $options['pathOnly'] : false;
$options['detectBrowser'] = isset($options['detectBrowser']) ? $options['detectBrowser'] : true;
$options['detectDebug'] = isset($options['detectDebug']) ? $options['detectDebug'] : true;
$options['framework'] = $options['framework'] ?? false;
$options['relative'] = $options['relative'] ?? false;
$options['pathOnly'] = $options['pathOnly'] ?? false;
$options['detectBrowser'] = $options['detectBrowser'] ?? true;
$options['detectDebug'] = $options['detectDebug'] ?? true;
}

// Include MooTools framework
Expand Down Expand Up @@ -1173,15 +1173,15 @@ public static function calendar($value, $name, $id, $format = '%Y-%m-%d', $attri
$autofocus = isset($attribs['autofocus']) && $attribs['autofocus'] === '';
$required = isset($attribs['required']) && $attribs['required'] === '';
$filter = isset($attribs['filter']) && $attribs['filter'] === '';
$todayBtn = isset($attribs['todayBtn']) ? $attribs['todayBtn'] : true;
$weekNumbers = isset($attribs['weekNumbers']) ? $attribs['weekNumbers'] : true;
$showTime = isset($attribs['showTime']) ? $attribs['showTime'] : false;
$fillTable = isset($attribs['fillTable']) ? $attribs['fillTable'] : true;
$timeFormat = isset($attribs['timeFormat']) ? $attribs['timeFormat'] : 24;
$singleHeader = isset($attribs['singleHeader']) ? $attribs['singleHeader'] : false;
$hint = isset($attribs['placeholder']) ? $attribs['placeholder'] : '';
$class = isset($attribs['class']) ? $attribs['class'] : '';
$onchange = isset($attribs['onChange']) ? $attribs['onChange'] : '';
$todayBtn = $attribs['todayBtn'] ?? true;
$weekNumbers = $attribs['weekNumbers'] ?? true;
$showTime = $attribs['showTime'] ?? false;
$fillTable = $attribs['fillTable'] ?? true;
$timeFormat = $attribs['timeFormat'] ?? 24;
$singleHeader = $attribs['singleHeader'] ?? false;
$hint = $attribs['placeholder'] ?? '';
$class = $attribs['class'] ?? '';
$onchange = $attribs['onChange'] ?? '';

$showTime = ($showTime) ? "1" : "0";
$todayBtn = ($todayBtn) ? "1" : "0";
Expand Down
2 changes: 1 addition & 1 deletion libraries/src/Helper/ContentHistoryHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ public function store($table)
// Load history_limit config from extension.
$aliasParts = explode('.', $this->typeAlias);

$context = isset($aliasParts[1]) ? $aliasParts[1] : '';
$context = $aliasParts[1] ?? '';

$maxVersionsContext = ComponentHelper::getParams($aliasParts[0])->get('history_limit' . '_' . $context, 0);

Expand Down
2 changes: 1 addition & 1 deletion libraries/src/Helper/MediaHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ private function getMimeType($file, $isImage = false)
elseif ($isImage && function_exists('getimagesize'))
{
$imagesize = getimagesize($file);
$mime = isset($imagesize['mime']) ? $imagesize['mime'] : false;
$mime = $imagesize['mime'] ?? false;
}
elseif (function_exists('mime_content_type'))
{
Expand Down
2 changes: 1 addition & 1 deletion libraries/src/Helper/RouteHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ protected function findItem($needles = array())
{
$app = \JFactory::getApplication();
$menus = $app->getMenu('site');
$language = isset($needles['language']) ? $needles['language'] : '*';
$language = $needles['language'] ?? '*';

// $this->extension may not be set if coming from a static method, check it
if ($this->extension === null)
Expand Down
2 changes: 1 addition & 1 deletion libraries/src/Http/Transport/CurlTransport.php
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ protected function getResponse($content, $info)
else
{
// Get the number of redirects that occurred.
$redirects = isset($info['redirect_count']) ? $info['redirect_count'] : 0;
$redirects = $info['redirect_count'] ?? 0;

/*
* Split the response into headers and body. If cURL encountered redirects, the headers for the redirected requests will
Expand Down
2 changes: 1 addition & 1 deletion libraries/src/Input/Cli.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ protected function parseArguments()
}
else
{
$value = isset($out[$key]) ? $out[$key] : true;
$value = $out[$key] ?? true;
}

$out[$key] = $value;
Expand Down
2 changes: 1 addition & 1 deletion libraries/src/Input/Input.php
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ protected function getArrayRecursive(array $vars = array(), $datasource = null,
}
else
{
$filter = isset($defaultFilter) ? $defaultFilter : $v;
$filter = $defaultFilter ?? $v;

if (is_null($datasource))
{
Expand Down
4 changes: 2 additions & 2 deletions libraries/src/Language/Language.php
Original file line number Diff line number Diff line change
Expand Up @@ -1332,7 +1332,7 @@ public function getLocale()
*/
public function getFirstDay()
{
return (int) (isset($this->metadata['firstDay']) ? $this->metadata['firstDay'] : 0);
return (int) ($this->metadata['firstDay'] ?? 0);
}

/**
Expand All @@ -1344,7 +1344,7 @@ public function getFirstDay()
*/
public function getWeekEnd()
{
return (isset($this->metadata['weekEnd']) && $this->metadata['weekEnd']) ? $this->metadata['weekEnd'] : '0,6';
return $this->metadata['weekEnd'] ?? '0,6';
}

/**
Expand Down
2 changes: 1 addition & 1 deletion libraries/src/Language/LanguageHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public static function createLanguageList($actualLanguage, $basePath = JPATH_BAS
$metadata = $installed ? $language->metadata : $language;

$list[] = array(
'text' => isset($metadata['nativeName']) ? $metadata['nativeName'] : $metadata['name'],
'text' => $metadata['nativeName'] ?? $metadata['name'],
'value' => $languageCode,
'selected' => $languageCode === $actualLanguage ? 'selected="selected"' : null,
);
Expand Down
2 changes: 1 addition & 1 deletion libraries/src/Layout/BaseLayout.php
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ public function debug($data = array())
*/
public function get($key, $defaultValue = null)
{
return isset($this->data[$key]) ? $this->data[$key] : $defaultValue;
return $this->data[$key] ?? $defaultValue;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion libraries/src/MVC/Controller/FormController.php
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ protected function allowEdit($data = array(), $key = 'id')
*/
protected function allowSave($data, $key = 'id')
{
$recordId = isset($data[$key]) ? $data[$key] : '0';
$recordId = $data[$key] ?? '0';

if ($recordId)
{
Expand Down

0 comments on commit 2dff49d

Please sign in to comment.