Browse Source

Use null coalesce operator where possible

Added ternary_to_null_coalescing to php-cs-fixer config

Related to #11397
tags/3.0.0-alpha1
SilverFire - Dmitry Naumenko 6 years ago
parent
commit
1cc5f15635
No known key found for this signature in database
GPG Key ID: 39DD917A92B270A
  1. 3
      cs/src/YiiConfig.php
  2. 2
      framework/base/Application.php
  3. 4
      framework/base/Model.php
  4. 6
      framework/console/Controller.php
  5. 2
      framework/console/ExitCode.php
  6. 4
      framework/console/Request.php
  7. 5
      framework/console/controllers/MigrateController.php
  8. 7
      framework/console/widgets/Table.php
  9. 4
      framework/data/Sort.php
  10. 8
      framework/db/ActiveRelationTrait.php
  11. 6
      framework/db/Command.php
  12. 4
      framework/db/Schema.php
  13. 2
      framework/db/conditions/InConditionBuilder.php
  14. 4
      framework/db/pgsql/Schema.php
  15. 4
      framework/db/sqlite/Schema.php
  16. 2
      framework/filters/PageCache.php
  17. 4
      framework/grid/GridView.php
  18. 2
      framework/helpers/BaseArrayHelper.php
  19. 2
      framework/helpers/BaseConsole.php
  20. 4
      framework/helpers/BaseFileHelper.php
  21. 26
      framework/helpers/BaseHtml.php
  22. 4
      framework/helpers/BaseIpHelper.php
  23. 2
      framework/helpers/BaseStringHelper.php
  24. 2
      framework/helpers/BaseVarDumper.php
  25. 6
      framework/rbac/PhpManager.php
  26. 2
      framework/test/BaseActiveFixture.php
  27. 6
      framework/test/FixtureTrait.php
  28. 2
      framework/validators/IpValidator.php
  29. 2
      framework/web/MultiFieldSession.php
  30. 4
      framework/web/Request.php
  31. 4
      framework/web/Response.php
  32. 8
      framework/web/Session.php
  33. 2
      framework/web/UrlRule.php
  34. 4
      framework/widgets/DetailView.php
  35. 2
      framework/widgets/Menu.php
  36. 2
      tests/TestCase.php
  37. 6
      tests/framework/console/controllers/CacheControllerTest.php
  38. 2
      tests/framework/db/CommandTest.php
  39. 2
      tests/framework/db/pgsql/ActiveRecordTest.php
  40. 2
      tests/framework/log/LoggerDispatchingTest.php
  41. 2
      tests/framework/log/SyslogTargetTest.php
  42. 8
      tests/framework/validators/FileValidatorTest.php

3
cs/src/YiiConfig.php

@ -147,8 +147,9 @@ class YiiConfig extends Config
'single_blank_line_before_namespace' => true,
'single_quote' => true,
'standardize_not_equals' => true,
'ternary_operator_spaces' => true,
'trailing_comma_in_multiline_array' => true,
'ternary_operator_spaces' => true,
'ternary_to_null_coalescing' => true,
'trim_array_spaces' => true,
'unary_operator_spaces' => true,
'whitespace_after_comma_in_array' => true,

2
framework/base/Application.php

@ -403,7 +403,7 @@ abstract class Application extends Module
return $response->exitStatus;
} catch (ExitException $e) {
$this->end($e->statusCode, isset($response) ? $response : null);
$this->end($e->statusCode, $response ?? null);
return $e->statusCode;
}
}

4
framework/base/Model.php

@ -522,7 +522,7 @@ class Model extends Component implements StaticInstanceInterface, IteratorAggreg
public function getAttributeLabel($attribute)
{
$labels = $this->attributeLabels();
return isset($labels[$attribute]) ? $labels[$attribute] : $this->generateAttributeLabel($attribute);
return $labels[$attribute] ?? $this->generateAttributeLabel($attribute);
}
/**
@ -535,7 +535,7 @@ class Model extends Component implements StaticInstanceInterface, IteratorAggreg
public function getAttributeHint($attribute)
{
$hints = $this->attributeHints();
return isset($hints[$attribute]) ? $hints[$attribute] : '';
return $hints[$attribute] ?? '';
}
/**

6
framework/console/Controller.php

@ -290,7 +290,7 @@ class Controller extends \yii\base\Controller
return Console::prompt($text, $options);
}
return isset($options['default']) ? $options['default'] : '';
return $options['default'] ?? '';
}
/**
@ -488,7 +488,7 @@ class Controller extends \yii\base\Controller
continue;
}
$name = $reflection->getName();
$tag = isset($params[$i]) ? $params[$i] : '';
$tag = $params[$i] ?? '';
if (preg_match('/^(\S+)\s+(\$\w+\s+)?(.*)/s', $tag, $matches)) {
$type = $matches[1];
$comment = $matches[3];
@ -553,7 +553,7 @@ class Controller extends \yii\base\Controller
$name = Inflector::camel2id($name, '-', true);
if (isset($tags['var']) || isset($tags['property'])) {
$doc = isset($tags['var']) ? $tags['var'] : $tags['property'];
$doc = $tags['var'] ?? $tags['property'];
if (is_array($doc)) {
$doc = reset($doc);
}

2
framework/console/ExitCode.php

@ -155,6 +155,6 @@ class ExitCode
*/
public static function getReason($exitCode)
{
return isset(static::$reasons[$exitCode]) ? static::$reasons[$exitCode] : 'Unknown exit code';
return static::$reasons[$exitCode] ?? 'Unknown exit code';
}
}

4
framework/console/Request.php

@ -84,7 +84,7 @@ class Request extends \yii\base\Request
}
if ($name !== Application::OPTION_APPCONFIG) {
$params[$name] = isset($matches[2]) ? $matches[2] : true;
$params[$name] = $matches[2] ?? true;
$prevOption = &$params[$name];
}
} elseif (preg_match('/^-([\w-]+)(?:=(.*))?$/', $param, $matches)) {
@ -92,7 +92,7 @@ class Request extends \yii\base\Request
if (is_numeric($name)) {
$params[] = $param;
} else {
$params['_aliases'][$name] = isset($matches[2]) ? $matches[2] : true;
$params['_aliases'][$name] = $matches[2] ?? true;
$prevOption = &$params['_aliases'][$name];
}
} elseif ($prevOption === true) {

5
framework/console/controllers/MigrateController.php

@ -486,9 +486,8 @@ class MigrateController extends BaseMigrateController
if (strncmp($chunk, 'foreignKey', 10) === 0) {
preg_match('/foreignKey\((\w*)\s?(\w*)\)/', $chunk, $matches);
$foreignKeys[$property] = [
'table' => isset($matches[1])
? $matches[1]
: preg_replace('/_id$/', '', $property),
'table' => $matches[1]
?? preg_replace('/_id$/', '', $property),
'column' => !empty($matches[2])
? $matches[2]
: null,

7
framework/console/widgets/Table.php

@ -231,7 +231,7 @@ class Table extends Widget
for ($i = 0, ($max = $this->calculateRowHeight($row)) ?: $max = 1; $i < $max; $i++) {
$buffer .= $spanLeft . ' ';
foreach ($size as $index => $cellSize) {
$cell = isset($row[$index]) ? $row[$index] : null;
$cell = $row[$index] ?? null;
$prefix = '';
if ($index !== 0) {
$buffer .= $spanMiddle . ' ';
@ -377,9 +377,8 @@ class Table extends Widget
{
if (!$this->_screenWidth) {
$size = Console::getScreenSize();
$this->_screenWidth = isset($size[0])
? $size[0]
: self::DEFAULT_CONSOLE_SCREEN_WIDTH + self::CONSOLE_SCROLLBAR_OFFSET;
$this->_screenWidth = $size[0]
?? self::DEFAULT_CONSOLE_SCREEN_WIDTH + self::CONSOLE_SCROLLBAR_OFFSET;
}
return $this->_screenWidth;
}

4
framework/data/Sort.php

@ -344,7 +344,7 @@ class Sort extends BaseObject
{
$orders = $this->getAttributeOrders();
return isset($orders[$attribute]) ? $orders[$attribute] : null;
return $orders[$attribute] ?? null;
}
/**
@ -435,7 +435,7 @@ class Sort extends BaseObject
$direction = $directions[$attribute] === SORT_DESC ? SORT_ASC : SORT_DESC;
unset($directions[$attribute]);
} else {
$direction = isset($definition['default']) ? $definition['default'] : SORT_ASC;
$direction = $definition['default'] ?? SORT_ASC;
}
if ($this->enableMultiSort) {

8
framework/db/ActiveRelationTrait.php

@ -297,7 +297,7 @@ trait ActiveRelationTrait
}
} else {
$key = $this->getModelKey($primaryModel, $link);
$value = isset($buckets[$key]) ? $buckets[$key] : ($this->multiple ? [] : null);
$value = $buckets[$key] ?? ($this->multiple ? [] : null);
}
if ($primaryModel instanceof ActiveRecordInterface) {
$primaryModel->populateRelation($name, $value);
@ -338,18 +338,18 @@ trait ActiveRelationTrait
if ($model instanceof ActiveRecordInterface) {
foreach ($models as $model) {
$key = $this->getModelKey($model, $relation->link);
$model->populateRelation($name, isset($buckets[$key]) ? $buckets[$key] : []);
$model->populateRelation($name, $buckets[$key] ?? []);
}
} else {
foreach ($primaryModels as $i => $primaryModel) {
if ($this->multiple) {
foreach ($primaryModel as $j => $m) {
$key = $this->getModelKey($m, $relation->link);
$primaryModels[$i][$j][$name] = isset($buckets[$key]) ? $buckets[$key] : [];
$primaryModels[$i][$j][$name] = $buckets[$key] ?? [];
}
} elseif (!empty($primaryModel[$primaryName])) {
$key = $this->getModelKey($primaryModel[$primaryName], $relation->link);
$primaryModels[$i][$primaryName][$name] = isset($buckets[$key]) ? $buckets[$key] : [];
$primaryModels[$i][$primaryName][$name] = $buckets[$key] ?? [];
}
}
}

6
framework/db/Command.php

@ -220,7 +220,7 @@ class Command extends Component
}
$sql = '';
foreach (explode('?', $this->_sql) as $i => $part) {
$sql .= (isset($params[$i]) ? $params[$i] : '') . $part;
$sql .= ($params[$i] ?? '') . $part;
}
return $sql;
@ -1100,10 +1100,10 @@ class Command extends Component
Yii::info($rawSql, $category);
}
if (!$this->db->enableProfiling) {
return [false, isset($rawSql) ? $rawSql : null];
return [false, $rawSql ?? null];
}
return [true, isset($rawSql) ? $rawSql : $this->getRawSql()];
return [true, $rawSql ?? $this->getRawSql()];
}
/**

4
framework/db/Schema.php

@ -270,7 +270,7 @@ abstract class Schema extends BaseObject
];
$type = gettype($data);
return isset($typeMap[$type]) ? $typeMap[$type] : \PDO::PARAM_STR;
return $typeMap[$type] ?? \PDO::PARAM_STR;
}
/**
@ -441,7 +441,7 @@ abstract class Schema extends BaseObject
break;
}
$result[$name] = isset($columns[$name]) ? $columns[$name] : $tableSchema->columns[$name]->defaultValue;
$result[$name] = $columns[$name] ?? $tableSchema->columns[$name]->defaultValue;
}
return $result;

2
framework/db/conditions/InConditionBuilder.php

@ -90,7 +90,7 @@ class InConditionBuilder implements ExpressionBuilderInterface
foreach ($values as $i => $value) {
if (is_array($value) || $value instanceof \ArrayAccess) {
$value = isset($value[$column]) ? $value[$column] : null;
$value = $value[$column] ?? null;
}
if ($value === null) {
$sqlValues[$i] = 'NULL';

4
framework/db/pgsql/Schema.php

@ -695,8 +695,8 @@ SQL;
'foreignSchemaName' => $constraint[0]['foreign_table_schema'],
'foreignTableName' => $constraint[0]['foreign_table_name'],
'foreignColumnNames' => array_keys(array_count_values(ArrayHelper::getColumn($constraint, 'foreign_column_name'))),
'onDelete' => isset($actionTypes[$constraint[0]['on_delete']]) ? $actionTypes[$constraint[0]['on_delete']] : null,
'onUpdate' => isset($actionTypes[$constraint[0]['on_update']]) ? $actionTypes[$constraint[0]['on_update']] : null,
'onDelete' => $actionTypes[$constraint[0]['on_delete']] ?? null,
'onUpdate' => $actionTypes[$constraint[0]['on_update']] ?? null,
]);
break;
case 'u':

4
framework/db/sqlite/Schema.php

@ -127,8 +127,8 @@ class Schema extends \yii\db\Schema implements ConstraintFinderInterface
'columnNames' => ArrayHelper::getColumn($foreignKey, 'from'),
'foreignTableName' => $table,
'foreignColumnNames' => ArrayHelper::getColumn($foreignKey, 'to'),
'onDelete' => isset($foreignKey[0]['on_delete']) ? $foreignKey[0]['on_delete'] : null,
'onUpdate' => isset($foreignKey[0]['on_update']) ? $foreignKey[0]['on_update'] : null,
'onDelete' => $foreignKey[0]['on_delete'] ?? null,
'onUpdate' => $foreignKey[0]['on_update'] ?? null,
]);
}

2
framework/filters/PageCache.php

@ -226,7 +226,7 @@ class PageCache extends ActionFilter implements DynamicContentAwareInterface
if (!empty($data['dynamicPlaceholders']) && is_array($data['dynamicPlaceholders'])) {
$response->content = $this->updateDynamicContent($response->content, $data['dynamicPlaceholders'], true);
}
$this->afterRestoreResponse(isset($data['cacheData']) ? $data['cacheData'] : null);
$this->afterRestoreResponse($data['cacheData'] ?? null);
}
/**

4
framework/grid/GridView.php

@ -532,8 +532,8 @@ class GridView extends BaseListView
'__class' => $this->dataColumnClass ?: DataColumn::class,
'grid' => $this,
'attribute' => $matches[1],
'format' => isset($matches[3]) ? $matches[3] : 'text',
'label' => isset($matches[5]) ? $matches[5] : null,
'format' => $matches[3] ?? 'text',
'label' => $matches[5] ?? null,
]);
}

2
framework/helpers/BaseArrayHelper.php

@ -927,7 +927,7 @@ class BaseArrayHelper
foreach ($filters as $var) {
$keys = explode('.', $var);
$globalKey = $keys[0];
$localKey = isset($keys[1]) ? $keys[1] : null;
$localKey = $keys[1] ?? null;
if ($globalKey[0] === '!') {
$forbiddenVars[] = [

2
framework/helpers/BaseConsole.php

@ -814,7 +814,7 @@ class BaseConsole
} elseif ($options['validator'] &&
!call_user_func_array($options['validator'], [$input, &$error])
) {
static::output(isset($error) ? $error : $options['error']);
static::output($error ?? $options['error']);
goto top;
}

4
framework/helpers/BaseFileHelper.php

@ -303,7 +303,7 @@ class BaseFileHelper
}
$dstExists = is_dir($dst);
if (!$dstExists && (!isset($options['copyEmptyDirectories']) || $options['copyEmptyDirectories'])) {
static::createDirectory($dst, isset($options['dirMode']) ? $options['dirMode'] : 0775, true);
static::createDirectory($dst, $options['dirMode'] ?? 0775, true);
$dstExists = true;
}
@ -329,7 +329,7 @@ class BaseFileHelper
if (is_file($from)) {
if (!$dstExists) {
// delay creation of destination directory until the first file is copied to avoid creating empty directories
static::createDirectory($dst, isset($options['dirMode']) ? $options['dirMode'] : 0775, true);
static::createDirectory($dst, $options['dirMode'] ?? 0775, true);
$dstExists = true;
}
copy($from, $to);

26
framework/helpers/BaseHtml.php

@ -766,7 +766,7 @@ class BaseHtml
}
if (isset($options['label'])) {
$label = $options['label'];
$labelOptions = isset($options['labelOptions']) ? $options['labelOptions'] : [];
$labelOptions = $options['labelOptions'] ?? [];
unset($options['label'], $options['labelOptions']);
$content = static::label(static::input($type, $name, $value, $options) . ' ' . $label, null, $labelOptions);
return $hidden . $content;
@ -1190,7 +1190,7 @@ class BaseHtml
public static function activeHint($model, $attribute, $options = [])
{
$attribute = static::getAttributeName($attribute);
$hint = isset($options['hint']) ? $options['hint'] : $model->getAttributeHint($attribute);
$hint = $options['hint'] ?? $model->getAttributeHint($attribute);
if (empty($hint)) {
return '';
}
@ -1218,7 +1218,7 @@ class BaseHtml
*/
public static function errorSummary($models, $options = [])
{
$header = isset($options['header']) ? $options['header'] : '<p>' . Yii::t('yii', 'Please fix the following errors:') . '</p>';
$header = $options['header'] ?? '<p>' . Yii::t('yii', 'Please fix the following errors:') . '</p>';
$footer = ArrayHelper::remove($options, 'footer', '');
$encode = ArrayHelper::remove($options, 'encode', true);
$showAllErrors = ArrayHelper::remove($options, 'showAllErrors', false);
@ -1319,8 +1319,8 @@ class BaseHtml
*/
public static function activeInput($type, $model, $attribute, $options = [])
{
$name = isset($options['name']) ? $options['name'] : static::getInputName($model, $attribute);
$value = isset($options['value']) ? $options['value'] : static::getAttributeValue($model, $attribute);
$name = $options['name'] ?? static::getInputName($model, $attribute);
$value = $options['value'] ?? static::getAttributeValue($model, $attribute);
if (!array_key_exists('id', $options)) {
$options['id'] = static::getInputId($model, $attribute);
}
@ -1491,7 +1491,7 @@ class BaseHtml
*/
public static function activeTextarea($model, $attribute, $options = [])
{
$name = isset($options['name']) ? $options['name'] : static::getInputName($model, $attribute);
$name = $options['name'] ?? static::getInputName($model, $attribute);
if (isset($options['value'])) {
$value = $options['value'];
unset($options['value']);
@ -1552,7 +1552,7 @@ class BaseHtml
*/
protected static function activeBooleanInput($type, $model, $attribute, $options = [])
{
$name = isset($options['name']) ? $options['name'] : static::getInputName($model, $attribute);
$name = $options['name'] ?? static::getInputName($model, $attribute);
$value = static::getAttributeValue($model, $attribute);
if (!array_key_exists('value', $options)) {
@ -1788,8 +1788,8 @@ class BaseHtml
*/
protected static function activeListInput($type, $model, $attribute, $items, $options = [])
{
$name = isset($options['name']) ? $options['name'] : static::getInputName($model, $attribute);
$selection = isset($options['value']) ? $options['value'] : static::getAttributeValue($model, $attribute);
$name = $options['name'] ?? static::getInputName($model, $attribute);
$selection = $options['value'] ?? static::getAttributeValue($model, $attribute);
if (!array_key_exists('unselect', $options)) {
$options['unselect'] = '';
}
@ -1841,15 +1841,15 @@ class BaseHtml
$lines[] = static::tag('option', $promptText, $promptOptions);
}
$options = isset($tagOptions['options']) ? $tagOptions['options'] : [];
$groups = isset($tagOptions['groups']) ? $tagOptions['groups'] : [];
$options = $tagOptions['options'] ?? [];
$groups = $tagOptions['groups'] ?? [];
unset($tagOptions['prompt'], $tagOptions['options'], $tagOptions['groups']);
$options['encodeSpaces'] = ArrayHelper::getValue($options, 'encodeSpaces', $encodeSpaces);
$options['encode'] = ArrayHelper::getValue($options, 'encode', $encode);
foreach ($items as $key => $value) {
if (is_array($value)) {
$groupAttrs = isset($groups[$key]) ? $groups[$key] : [];
$groupAttrs = $groups[$key] ?? [];
if (!isset($groupAttrs['label'])) {
$groupAttrs['label'] = $key;
}
@ -1857,7 +1857,7 @@ class BaseHtml
$content = static::renderSelectOptions($selection, $value, $attrs);
$lines[] = static::tag('optgroup', "\n" . $content . "\n", $groupAttrs);
} else {
$attrs = isset($options[$key]) ? $options[$key] : [];
$attrs = $options[$key] ?? [];
$attrs['value'] = (string) $key;
if (!array_key_exists('selected', $attrs)) {
$attrs['selected'] = $selection !== null &&

4
framework/helpers/BaseIpHelper.php

@ -75,8 +75,8 @@ class BaseIpHelper
}
$maxMask = $ipVersion === self::IPV4 ? self::IPV4_ADDRESS_LENGTH : self::IPV6_ADDRESS_LENGTH;
$mask = isset($mask) ? $mask : $maxMask;
$netMask = isset($netMask) ? $netMask : $maxMask;
$mask = $mask ?? $maxMask;
$netMask = $netMask ?? $maxMask;
$binIp = static::ip2bin($ip);
$binNet = static::ip2bin($net);

2
framework/helpers/BaseStringHelper.php

@ -310,7 +310,7 @@ class BaseStringHelper
$value = (string)$value;
$localeInfo = localeconv();
$decimalSeparator = isset($localeInfo['decimal_point']) ? $localeInfo['decimal_point'] : null;
$decimalSeparator = $localeInfo['decimal_point'] ?? null;
if ($decimalSeparator !== null && $decimalSeparator !== '.') {
$value = str_replace($decimalSeparator, '.', $value);

2
framework/helpers/BaseVarDumper.php

@ -255,7 +255,7 @@ class BaseVarDumper
continue;
}
if ($closureTokens !== []) {
$closureTokens[] = isset($token[1]) ? $token[1] : $token;
$closureTokens[] = $token[1] ?? $token;
if ($token === '}') {
$pendingParenthesisCount--;
if ($pendingParenthesisCount === 0) {

6
framework/rbac/PhpManager.php

@ -725,9 +725,9 @@ class PhpManager extends BaseManager
$this->items[$name] = new $class([
'name' => $name,
'description' => isset($item['description']) ? $item['description'] : null,
'ruleName' => isset($item['ruleName']) ? $item['ruleName'] : null,
'data' => isset($item['data']) ? $item['data'] : null,
'description' => $item['description'] ?? null,
'ruleName' => $item['ruleName'] ?? null,
'data' => $item['data'] ?? null,
'createdAt' => $itemsMtime,
'updatedAt' => $itemsMtime,
]);

2
framework/test/BaseActiveFixture.php

@ -62,7 +62,7 @@ abstract class BaseActiveFixture extends DbFixture implements \IteratorAggregate
$modelClass = $this->modelClass;
$keys = [];
foreach ($modelClass::primaryKey() as $key) {
$keys[$key] = isset($row[$key]) ? $row[$key] : null;
$keys[$key] = $row[$key] ?? null;
}
return $this->_models[$name] = $modelClass::findOne($keys);

6
framework/test/FixtureTrait.php

@ -197,18 +197,18 @@ trait FixtureTrait
while (($fixture = array_pop($stack)) !== null) {
if ($fixture instanceof Fixture) {
$class = get_class($fixture);
$name = isset($aliases[$class]) ? $aliases[$class] : $class;
$name = $aliases[$class] ?? $class;
unset($instances[$name]); // unset so that the fixture is added to the last in the next line
$instances[$name] = $fixture;
} else {
$class = ltrim($fixture['__class'], '\\');
$name = isset($aliases[$class]) ? $aliases[$class] : $class;
$name = $aliases[$class] ?? $class;
if (!isset($instances[$name])) {
$instances[$name] = false;
$stack[] = $fixture = Yii::createObject($fixture);
foreach ($fixture->depends as $dep) {
// need to use the configuration provided in test case
$stack[] = isset($config[$dep]) ? $config[$dep] : ['__class' => $dep];
$stack[] = $config[$dep] ?? ['__class' => $dep];
}
} elseif ($instances[$name] === false) {
throw new InvalidConfigException("A circular dependency is detected for fixture '$class'.");

2
framework/validators/IpValidator.php

@ -331,7 +331,7 @@ class IpValidator extends Validator
if (preg_match($this->getIpParsePattern(), $ip, $matches)) {
$negation = ($matches[1] !== '') ? $matches[1] : null;
$ip = $matches[2];
$cidr = isset($matches[4]) ? $matches[4] : null;
$cidr = $matches[4] ?? null;
}
if ($this->subnet === true && $cidr === null) {

2
framework/web/MultiFieldSession.php

@ -137,6 +137,6 @@ abstract class MultiFieldSession extends Session
return $fields['data'];
}
return isset($fields['data']) ? $fields['data'] : '';
return $fields['data'] ?? '';
}
}

4
framework/web/Request.php

@ -761,7 +761,7 @@ class Request extends \yii\base\Request implements ServerRequestInterface
}
}
return isset($params[$name]) ? $params[$name] : $defaultValue;
return $params[$name] ?? $defaultValue;
}
/**
@ -851,7 +851,7 @@ class Request extends \yii\base\Request implements ServerRequestInterface
{
$params = $this->getQueryParams();
return isset($params[$name]) ? $params[$name] : $defaultValue;
return $params[$name] ?? $defaultValue;
}
/**

4
framework/web/Response.php

@ -548,7 +548,7 @@ class Response extends \yii\base\Response implements ResponseInterface
$body->write($content);
}
$mimeType = isset($options['mimeType']) ? $options['mimeType'] : 'application/octet-stream';
$mimeType = $options['mimeType'] ?? 'application/octet-stream';
$this->setDownloadHeaders($attachmentName, $mimeType, !empty($options['inline']), $end - $begin + 1);
$this->format = self::FORMAT_RAW;
@ -600,7 +600,7 @@ class Response extends \yii\base\Response implements ResponseInterface
$this->setStatusCode(200);
}
$mimeType = isset($options['mimeType']) ? $options['mimeType'] : 'application/octet-stream';
$mimeType = $options['mimeType'] ?? 'application/octet-stream';
$this->setDownloadHeaders($attachmentName, $mimeType, !empty($options['inline']), $end - $begin + 1);
$this->format = self::FORMAT_RAW;

8
framework/web/Session.php

@ -141,7 +141,7 @@ class Session extends Component implements \IteratorAggregate, \ArrayAccess, \Co
$this->updateFlashCounters();
} else {
$error = error_get_last();
$message = isset($error['message']) ? $error['message'] : 'Failed to start session.';
$message = $error['message'] ?? 'Failed to start session.';
Yii::error($message, __METHOD__);
}
}
@ -611,7 +611,7 @@ class Session extends Component implements \IteratorAggregate, \ArrayAccess, \Co
public function get($key, $defaultValue = null)
{
$this->open();
return isset($_SESSION[$key]) ? $_SESSION[$key] : $defaultValue;
return $_SESSION[$key] ?? $defaultValue;
}
/**
@ -895,7 +895,7 @@ class Session extends Component implements \IteratorAggregate, \ArrayAccess, \Co
{
$this->open();
return isset($_SESSION[$offset]) ? $_SESSION[$offset] : null;
return $_SESSION[$offset] ?? null;
}
/**
@ -949,7 +949,7 @@ class Session extends Component implements \IteratorAggregate, \ArrayAccess, \Co
Yii::info('Session unfrozen', __METHOD__);
} else {
$error = error_get_last();
$message = isset($error['message']) ? $error['message'] : 'Failed to unfreeze session.';
$message = $error['message'] ?? 'Failed to unfreeze session.';
Yii::error($message, __METHOD__);
}

2
framework/web/UrlRule.php

@ -284,7 +284,7 @@ class UrlRule extends BaseObject implements UrlRuleInterface
$appendSlash = false;
foreach ($matches as $match) {
$name = $match[1][0];
$pattern = isset($match[2][0]) ? $match[2][0] : '[^\/]+';
$pattern = $match[2][0] ?? '[^\/]+';
$placeholder = 'a' . hash('crc32b', $name); // placeholder must begin with a letter
$this->placeholders[$placeholder] = $name;
if (array_key_exists($name, $this->defaults)) {

4
framework/widgets/DetailView.php

@ -213,8 +213,8 @@ class DetailView extends Widget
}
$attribute = [
'attribute' => $matches[1],
'format' => isset($matches[3]) ? $matches[3] : 'text',
'label' => isset($matches[5]) ? $matches[5] : null,
'format' => $matches[3] ?? 'text',
'label' => $matches[5] ?? null,
];
}

2
framework/widgets/Menu.php

@ -266,7 +266,7 @@ class Menu extends Widget
if (!isset($item['label'])) {
$item['label'] = '';
}
$encodeLabel = isset($item['encode']) ? $item['encode'] : $this->encodeLabels;
$encodeLabel = $item['encode'] ?? $this->encodeLabels;
$items[$i]['label'] = $encodeLabel ? Html::encode($item['label']) : $item['label'];
$hasActiveChild = false;
if (isset($item['items'])) {

2
tests/TestCase.php

@ -29,7 +29,7 @@ abstract class TestCase extends \PHPUnit\Framework\TestCase
static::$params = require __DIR__ . '/data/config.php';
}
return isset(static::$params[$name]) ? static::$params[$name] : $default;
return static::$params[$name] ?? $default;
}
/**

6
tests/framework/console/controllers/CacheControllerTest.php

@ -55,10 +55,10 @@ class CacheControllerTest extends TestCase
},
'session' => 'yii\web\CacheSession', // should be ignored at `actionFlushAll()`
'db' => [
'__class' => isset($config['__class']) ? $config['__class'] : \yii\db\Connection::class,
'__class' => $config['__class'] ?? \yii\db\Connection::class,
'dsn' => $config['dsn'],
'username' => isset($config['username']) ? $config['username'] : null,
'password' => isset($config['password']) ? $config['password'] : null,
'username' => $config['username'] ?? null,
'password' => $config['password'] ?? null,
'enableSchemaCache' => true,
'schemaCache' => 'firstCache',
],

2
tests/framework/db/CommandTest.php

@ -1018,7 +1018,7 @@ SQL;
protected function performAndCompareUpsertResult(Connection $db, array $data)
{
$params = $data['params'];
$expected = isset($data['expected']) ? $data['expected'] : $params[1];
$expected = $data['expected'] ?? $params[1];
$command = $db->createCommand();
call_user_func_array([$command, 'upsert'], $params);
$command->execute();

2
tests/framework/db/pgsql/ActiveRecordTest.php

@ -191,7 +191,7 @@ class ActiveRecordTest extends \yiiunit\framework\db\ActiveRecordTest
$type = ArrayAndJsonTypes::find()->one();
foreach ($attributes as $attribute => $expected) {
$expected = isset($expected[1]) ? $expected[1] : $expected[0];
$expected = $expected[1] ?? $expected[0];
$value = $type->$attribute;
$this->assertEquals($expected, $value, 'In column ' . $attribute);

2
tests/framework/log/LoggerDispatchingTest.php

@ -166,7 +166,7 @@ namespace yiiunit\framework\log {
public static function __callStatic($name, $arguments)
{
if (isset(static::$functions[$name]) && is_callable(static::$functions[$name])) {
$arguments = isset($arguments[0]) ? $arguments[0] : $arguments;
$arguments = $arguments[0] ?? $arguments;
return forward_static_call(static::$functions[$name], $arguments);
}
static::fail("Function '$name' has not implemented yet!");

2
tests/framework/log/SyslogTargetTest.php

@ -197,7 +197,7 @@ namespace yiiunit\framework\log {
public static function __callStatic($name, $arguments)
{
if (isset(static::$functions[$name]) && is_callable(static::$functions[$name])) {
$arguments = isset($arguments[0]) ? $arguments[0] : $arguments;
$arguments = $arguments[0] ?? $arguments;
return forward_static_call(static::$functions[$name], $arguments);
}
static::fail("Function '$name' has not implemented yet!");

8
tests/framework/validators/FileValidatorTest.php

@ -338,18 +338,18 @@ class FileValidatorTest extends TestCase
$files[$key] = ['no instance of UploadedFile'];
continue;
}
$name = isset($param['clientFilename']) ? $param['clientFilename'] : $rndString();
$name = $param['clientFilename'] ?? $rndString();
$tempName = \Yii::getAlias('@yiiunit/runtime/validators/file/tmp/') . $name;
if (is_readable($tempName)) {
$size = filesize($tempName);
} else {
$size = isset($param['size']) ? $param['size'] : rand(
$size = $param['size'] ?? rand(
1,
$this->sizeToBytes(ini_get('upload_max_filesize'))
);
}
$type = isset($param['clientMediaType']) ? $param['clientMediaType'] : 'text/plain';
$error = isset($param['error']) ? $param['error'] : UPLOAD_ERR_OK;
$type = $param['clientMediaType'] ?? 'text/plain';
$error = $param['error'] ?? UPLOAD_ERR_OK;
if (count($params) == 1) {
$error = empty($param) ? UPLOAD_ERR_NO_FILE : $error;

Loading…
Cancel
Save