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 coalescing operator #2543

Merged
merged 10 commits into from
Sep 12, 2022
5 changes: 0 additions & 5 deletions .github/phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -3215,11 +3215,6 @@ parameters:
count: 1
path: ../app/code/core/Mage/Sales/Model/Order/Api.php

-
message: "#^Variable \\$data in isset\\(\\) always exists and is not nullable\\.$#"
count: 1
path: ../app/code/core/Mage/Sales/Model/Order/Creditmemo/Api.php

-
message: "#^Cannot call method addAttributeToFilter\\(\\) on Mage_Core_Model_Resource_Db_Collection_Abstract\\|false\\.$#"
count: 1
Expand Down
12 changes: 2 additions & 10 deletions app/code/core/Mage/Admin/Model/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,7 @@ public function getAclAssert($name = '')
return $asserts;
}

if (isset($asserts->$name)) {
return $asserts->$name;
}

return false;
return $asserts->$name ?? false;
}

/**
Expand All @@ -149,11 +145,7 @@ public function getAclPrivilegeSet($name = '')
return $sets;
}

if (isset($sets->$name)) {
return $sets->$name;
}

return false;
return $sets->$name ?? false;
}

/**
Expand Down
4 changes: 2 additions & 2 deletions app/code/core/Mage/Admin/Model/Observer.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ public function actionPreDispatchAdmin($observer)

if ($coreSession->validateFormKey($request->getPost("form_key"))) {
$postLogin = $request->getPost('login');
$username = isset($postLogin['username']) ? $postLogin['username'] : '';
$password = isset($postLogin['password']) ? $postLogin['password'] : '';
$username = $postLogin['username'] ?? '';
$password = $postLogin['password'] ?? '';
$session->login($username, $password, $request);
$request->setPost('login', null);
} else {
Expand Down
2 changes: 1 addition & 1 deletion app/code/core/Mage/Admin/Model/Session.php
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ public function login($username, $password, $request = null)
$this->_loginFailed($e, $request, $username, $message);
}

return isset($user) ? $user : null;
return $user ?? null;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion app/code/core/Mage/AdminNotification/Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public function getUnreadNoticeCount($severity)
if (is_null($this->_unreadNoticeCounts)) {
$this->_unreadNoticeCounts = Mage::getModel('adminnotification/inbox')->getNoticeStatus();
}
return isset($this->_unreadNoticeCounts[$severity]) ? $this->_unreadNoticeCounts[$severity] : 0;
return $this->_unreadNoticeCounts[$severity] ?? 0;
}

/**
Expand Down
5 changes: 1 addition & 4 deletions app/code/core/Mage/AdminNotification/Model/Inbox.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,7 @@ public function getSeverities($severity = null)
];

if (!is_null($severity)) {
if (isset($severities[$severity])) {
return $severities[$severity];
}
return null;
return $severities[$severity] ?? null;
}

return $severities;
Expand Down
2 changes: 1 addition & 1 deletion app/code/core/Mage/Adminhtml/Block/Api/Tab/Rolesedit.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public function getResTreeJson()

$rootArray = $this->_getNodeJson($resources,1);

return Mage::helper('core')->jsonEncode(isset($rootArray['children']) ? $rootArray['children'] : []);
return Mage::helper('core')->jsonEncode($rootArray['children'] ?? []);
}

protected function _sortTree($a, $b)
Expand Down
4 changes: 2 additions & 2 deletions app/code/core/Mage/Adminhtml/Block/Catalog/Category/Tree.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,13 +162,13 @@ public function getMoveUrl()
public function getTree($parenNodeCategory=null)
{
$rootArray = $this->_getNodeJson($this->getRoot($parenNodeCategory));
return isset($rootArray['children']) ? $rootArray['children'] : [];
return $rootArray['children'] ?? [];
}

public function getTreeJson($parenNodeCategory=null)
{
$rootArray = $this->_getNodeJson($this->getRoot($parenNodeCategory));
return Mage::helper('core')->jsonEncode(isset($rootArray['children']) ? $rootArray['children'] : []);
return Mage::helper('core')->jsonEncode($rootArray['children'] ?? []);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
}

$_parts = [];
$_parts[] = $element->setValue(isset($values[0]) ? $values[0] : null)->getElementHtml();
$_parts[] = $element->setValue(isset($values[1]) ? $values[1] : null)->getElementHtml();
$_parts[] = $element->setValue(isset($values[2]) ? $values[2] : null)->getElementHtml();
$_parts[] = $element->setValue($values[0] ?? null)->getElementHtml();
$_parts[] = $element->setValue($values[1] ?? null)->getElementHtml();
$_parts[] = $element->setValue($values[2] ?? null)->getElementHtml();

return implode(' <span>/</span> ', $_parts);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
$values = [];
}

$from = $element->setValue(isset($values[0]) ? $values[0] : null)->getElementHtml();
$to = $element->setValue(isset($values[1]) ? $values[1] : null)->getElementHtml();
$from = $element->setValue($values[0] ?? null)->getElementHtml();
$to = $element->setValue($values[1] ?? null)->getElementHtml();
return Mage::helper('adminhtml')->__('from') . ' ' . $from
. ' '
. Mage::helper('adminhtml')->__('to') . ' ' . $to;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ public function getCustomerGroups($groupId = null)
}

if ($groupId !== null) {
return isset($this->_customerGroups[$groupId]) ? $this->_customerGroups[$groupId] : [];
return $this->_customerGroups[$groupId] ?? [];
}

return $this->_customerGroups;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,6 @@ public function render(Varien_Object $row)

public static function getStatus($status)
{
if(isset(self::$_statuses[$status])) {
return self::$_statuses[$status];
}

return Mage::helper('customer')->__('Unknown');
return self::$_statuses[$status] ?? Mage::helper('customer')->__('Unknown');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,7 @@ protected function _getProductHelper($product)

// Check whether we have helper for our product
$productType = $product->getTypeId();
if (isset($productHelpers[$productType])) {
$helperName = $productHelpers[$productType];
} else if (isset($productHelpers['default'])) {
$helperName = $productHelpers['default'];
} else {
$helperName = 'catalog/product_configuration';
}
$helperName = $productHelpers[$productType] ?? $productHelpers['default'] ?? 'catalog/product_configuration';

$helper = Mage::helper($helperName);
if (!($helper instanceof Mage_Catalog_Helper_Product_Configuration_Interface)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public function _beforeToHtml()

public function getWebsiteCount($websiteId)
{
return isset($this->_websiteCounts[$websiteId]) ? $this->_websiteCounts[$websiteId] : 0;
return $this->_websiteCounts[$websiteId] ?? 0;
}

public function getRows()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ public function getResTreeJson()

$rootArray = $this->_getNodeJson($resources->admin, 1);

return Mage::helper('core')->jsonEncode(isset($rootArray['children']) ? $rootArray['children'] : []);
return Mage::helper('core')->jsonEncode($rootArray['children'] ?? []);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,8 @@ public function setRangeValues($from, $to)
public function setRangeValue($delimitedString)
{
$split = explode($this->_rangeDelimiter, $delimitedString, 2);
$from = $split[0]; $to = '';
if (isset($split[1])) {
$to = $split[1];
}
$from = $split[0];
$to = $split[1] ?? '';
return $this->setRangeValues($from, $to);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,12 @@ protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)

$_monthsHtml = $element->setStyle('width:100px;')
->setValues($_months)
->setValue(isset($values[0]) ? $values[0] : null)
->setValue($values[0] ?? null)
->getElementHtml();

$_daysHtml = $element->setStyle('width:50px;')
->setValues($_days)
->setValue(isset($values[1]) ? $values[1] : null)
->setValue($values[1] ?? null)
->getElementHtml();

return sprintf('%s %s', $_monthsHtml, $_daysHtml);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ protected function _prepareForm()
'name' => 'store_labels['.$store->getId().']',
'required' => false,
'label' => $store->getName(),
'value' => isset($labels[$store->getId()]) ? $labels[$store->getId()] : '',
'value' => $labels[$store->getId()] ?? '',
'fieldset_html_class' => 'store',
]);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ protected function _renderCellTemplate($columnName)

return '<input type="text" name="' . $inputName . '" value="#{' . $columnName . '}" ' .
($column['size'] ? 'size="' . $column['size'] . '"' : '') . ' class="' .
(isset($column['class']) ? $column['class'] : 'input-text') . '"'.
($column['class'] ?? 'input-text') . '"'.
(isset($column['style']) ? ' style="'.$column['style'] . '"' : '') . '/>';
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,9 +199,6 @@ protected function _getCollapseState($element)
return 1;
}
$extra = Mage::getSingleton('admin/session')->getUser()->getExtra();
if (isset($extra['configState'][$element->getId()])) {
return $extra['configState'][$element->getId()];
}
return false;
return $extra['configState'][$element->getId()] ?? false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,18 +64,18 @@ protected function _getFieldHtml($fieldset, $id, $status)
{
$configData = $this->getConfigData();
$path = 'sales/order_statuses/status_'.$id; //TODO: move as property of form
$data = isset($configData[$path]) ? $configData[$path] : [];
$data = $configData[$path] ?? [];

$e = $this->_getDummyElement();

$field = $fieldset->addField($id, 'text',
[
'name' => 'groups[order_statuses][fields][status_'.$id.'][value]',
'label' => $status,
'value' => isset($data['value']) ? $data['value'] : $status,
'default_value' => isset($data['default_value']) ? $data['default_value'] : '',
'old_value' => isset($data['old_value']) ? $data['old_value'] : '',
'inherit' => isset($data['inherit']) ? $data['inherit'] : '',
'value' => $data['value'] ?? $status,
'default_value' => $data['default_value'] ?? '',
'old_value' => $data['old_value'] ?? '',
'inherit' => $data['inherit'] ?? '',
'can_use_default_value' => $this->getForm()->canUseDefaultValue($e),
'can_use_website_value' => $this->getForm()->canUseWebsiteValue($e),
])->setRenderer($this->_getFieldRenderer());
Expand Down
6 changes: 1 addition & 5 deletions app/code/core/Mage/Adminhtml/Block/System/Config/Tabs.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,11 +153,7 @@ public function addTab($code, $config)
*/
public function getTab($code)
{
if(isset($this->_tabs[$code])) {
return $this->_tabs[$code];
}

return null;
return $this->_tabs[$code] ?? null;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,7 @@ class Mage_Adminhtml_Block_System_Email_Template_Grid_Renderer_Type
];
public function render(Varien_Object $row)
{

$str = Mage::helper('adminhtml')->__('Unknown');

if(isset(self::$_types[$row->getTemplateType()])) {
$str = self::$_types[$row->getTemplateType()];
}

$str = self::$_types[$row->getTemplateType()] ?? Mage::helper('adminhtml')->__('Unknown');
return Mage::helper('adminhtml')->__($str);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,7 @@ public function addItem($itemId, array $item)
*/
public function getItem($itemId)
{
if(isset($this->_items[$itemId])) {
return $this->_items[$itemId];
}

return null;
return $this->_items[$itemId] ?? null;
}

/**
Expand Down
8 changes: 2 additions & 6 deletions app/code/core/Mage/Adminhtml/Helper/Dashboard/Abstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,15 +97,11 @@ public function setParams(array $params)

public function getParam($name)
{
if(isset($this->_params[$name])) {
return $this->_params[$name];
}

return null;
return $this->_params[$name] ?? null;
}

public function getParams()
{
return $this->_params;
}
}
}
6 changes: 1 addition & 5 deletions app/code/core/Mage/Adminhtml/Model/Giftmessage/Save.php
Original file line number Diff line number Diff line change
Expand Up @@ -324,11 +324,7 @@ protected function _getMappedType($type)
'order_item' => 'order_item'
];

if (isset($map[$type])) {
return $map[$type];
}

return null;
return $map[$type] ?? null;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion app/code/core/Mage/Adminhtml/Model/Sales/Order/Random.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ protected function _getRandomProduct()
{
$items = $this->_getProducts();
$randKey = array_rand($items);
return isset($items[$randKey]) ? $items[$randKey] : false;
return $items[$randKey] ?? false;
}

protected function _getStore()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,7 @@ protected function _afterSave()
];

$value = $this->getValue();
if (isset($valueConfig[$value])) {
$data = $valueConfig[$value];
} else {
$data = $valueConfig[''];
}
$data = $valueConfig[$value] ?? $valueConfig[''];

if ($this->getScope() == 'websites') {
$website = Mage::app()->getWebsite($this->getWebsiteCode());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class Mage_Adminhtml_Model_System_Config_Source_Security_Domainpolicy
*/
public function __construct($options = [])
{
$this->_helper = isset($options['helper']) ? $options['helper'] : Mage::helper('adminhtml');
$this->_helper = $options['helper'] ?? Mage::helper('adminhtml');
}

/**
Expand Down
5 changes: 1 addition & 4 deletions app/code/core/Mage/Adminhtml/Model/System/Store.php
Original file line number Diff line number Diff line change
Expand Up @@ -368,10 +368,7 @@ public function getStoreName($storeId)
**/
public function getStoreData($storeId)
{
if (isset($this->_storeCollection[$storeId])) {
return $this->_storeCollection[$storeId];
}
return null;
return $this->_storeCollection[$storeId] ?? null;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,11 +226,7 @@ public function saveAction()
&& Mage::helper('customer')->getIsRequireAdminUserToChangeUserPassword()
) {
//Validate current admin password
if (isset($data['account']['current_password'])) {
$currentPassword = $data['account']['current_password'];
} else {
$currentPassword = null;
}
$currentPassword = $data['account']['current_password'] ?? null;
unset($data['account']['current_password']);
$errors = $this->_validateCurrentPassword($currentPassword);
}
Expand Down
Loading