Skip to content

Commit 3c51a90

Browse files
authored
Use null coalescing operator (#2543)
1 parent d433ae9 commit 3c51a90

File tree

249 files changed

+434
-938
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

249 files changed

+434
-938
lines changed

.github/phpstan-baseline.neon

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3215,11 +3215,6 @@ parameters:
32153215
count: 1
32163216
path: ../app/code/core/Mage/Sales/Model/Order/Api.php
32173217

3218-
-
3219-
message: "#^Variable \\$data in isset\\(\\) always exists and is not nullable\\.$#"
3220-
count: 1
3221-
path: ../app/code/core/Mage/Sales/Model/Order/Creditmemo/Api.php
3222-
32233218
-
32243219
message: "#^Cannot call method addAttributeToFilter\\(\\) on Mage_Core_Model_Resource_Db_Collection_Abstract\\|false\\.$#"
32253220
count: 1

app/code/core/Mage/Admin/Model/Config.php

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -129,11 +129,7 @@ public function getAclAssert($name = '')
129129
return $asserts;
130130
}
131131

132-
if (isset($asserts->$name)) {
133-
return $asserts->$name;
134-
}
135-
136-
return false;
132+
return $asserts->$name ?? false;
137133
}
138134

139135
/**
@@ -149,11 +145,7 @@ public function getAclPrivilegeSet($name = '')
149145
return $sets;
150146
}
151147

152-
if (isset($sets->$name)) {
153-
return $sets->$name;
154-
}
155-
156-
return false;
148+
return $sets->$name ?? false;
157149
}
158150

159151
/**

app/code/core/Mage/Admin/Model/Observer.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ public function actionPreDispatchAdmin($observer)
6464

6565
if ($coreSession->validateFormKey($request->getPost("form_key"))) {
6666
$postLogin = $request->getPost('login');
67-
$username = isset($postLogin['username']) ? $postLogin['username'] : '';
68-
$password = isset($postLogin['password']) ? $postLogin['password'] : '';
67+
$username = $postLogin['username'] ?? '';
68+
$password = $postLogin['password'] ?? '';
6969
$session->login($username, $password, $request);
7070
$request->setPost('login', null);
7171
} else {

app/code/core/Mage/Admin/Model/Session.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ public function login($username, $password, $request = null)
189189
$this->_loginFailed($e, $request, $username, $message);
190190
}
191191

192-
return isset($user) ? $user : null;
192+
return $user ?? null;
193193
}
194194

195195
/**

app/code/core/Mage/AdminNotification/Helper/Data.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public function getUnreadNoticeCount($severity)
6565
if (is_null($this->_unreadNoticeCounts)) {
6666
$this->_unreadNoticeCounts = Mage::getModel('adminnotification/inbox')->getNoticeStatus();
6767
}
68-
return isset($this->_unreadNoticeCounts[$severity]) ? $this->_unreadNoticeCounts[$severity] : 0;
68+
return $this->_unreadNoticeCounts[$severity] ?? 0;
6969
}
7070

7171
/**

app/code/core/Mage/AdminNotification/Model/Inbox.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,7 @@ public function getSeverities($severity = null)
7171
];
7272

7373
if (!is_null($severity)) {
74-
if (isset($severities[$severity])) {
75-
return $severities[$severity];
76-
}
77-
return null;
74+
return $severities[$severity] ?? null;
7875
}
7976

8077
return $severities;

app/code/core/Mage/Adminhtml/Block/Api/Tab/Rolesedit.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public function getResTreeJson()
6464

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

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

7070
protected function _sortTree($a, $b)

app/code/core/Mage/Adminhtml/Block/Catalog/Category/Tree.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,13 +162,13 @@ public function getMoveUrl()
162162
public function getTree($parenNodeCategory=null)
163163
{
164164
$rootArray = $this->_getNodeJson($this->getRoot($parenNodeCategory));
165-
return isset($rootArray['children']) ? $rootArray['children'] : [];
165+
return $rootArray['children'] ?? [];
166166
}
167167

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

174174
/**

app/code/core/Mage/Adminhtml/Block/Catalog/Form/Renderer/Config/DateFieldsOrder.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@ protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
4646
}
4747

4848
$_parts = [];
49-
$_parts[] = $element->setValue(isset($values[0]) ? $values[0] : null)->getElementHtml();
50-
$_parts[] = $element->setValue(isset($values[1]) ? $values[1] : null)->getElementHtml();
51-
$_parts[] = $element->setValue(isset($values[2]) ? $values[2] : null)->getElementHtml();
49+
$_parts[] = $element->setValue($values[0] ?? null)->getElementHtml();
50+
$_parts[] = $element->setValue($values[1] ?? null)->getElementHtml();
51+
$_parts[] = $element->setValue($values[2] ?? null)->getElementHtml();
5252

5353
return implode(' <span>/</span> ', $_parts);
5454
}

app/code/core/Mage/Adminhtml/Block/Catalog/Form/Renderer/Config/YearRange.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
3838
$values = [];
3939
}
4040

41-
$from = $element->setValue(isset($values[0]) ? $values[0] : null)->getElementHtml();
42-
$to = $element->setValue(isset($values[1]) ? $values[1] : null)->getElementHtml();
41+
$from = $element->setValue($values[0] ?? null)->getElementHtml();
42+
$to = $element->setValue($values[1] ?? null)->getElementHtml();
4343
return Mage::helper('adminhtml')->__('from') . ' ' . $from
4444
. ' '
4545
. Mage::helper('adminhtml')->__('to') . ' ' . $to;

0 commit comments

Comments
 (0)