Skip to content
This repository was archived by the owner on Apr 29, 2019. It is now read-only.

Commit 5c578ed

Browse files
author
Stanislav Idolov
authored
ENGCOM-2996: Replace sort callbacks to spaceship operator #18102
2 parents 6539c5f + 5d7f1cd commit 5c578ed

File tree

10 files changed

+12
-55
lines changed

10 files changed

+12
-55
lines changed

app/code/Magento/Backend/Block/Widget/Button/ButtonList.php

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -127,12 +127,6 @@ public function getItems()
127127
*/
128128
public function sortButtons(Item $itemA, Item $itemB)
129129
{
130-
$sortOrderA = (int) $itemA->getSortOrder();
131-
$sortOrderB = (int) $itemB->getSortOrder();
132-
133-
if ($sortOrderA == $sortOrderB) {
134-
return 0;
135-
}
136-
return ($sortOrderA < $sortOrderB) ? -1 : 1;
130+
return (int)$itemA->getSortOrder() <=> (int)$itemB->getSortOrder();
137131
}
138132
}

app/code/Magento/Bundle/Model/Product/Type.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1014,10 +1014,8 @@ public function shakeSelections($firstItem, $secondItem)
10141014
$secondItem->getPosition(),
10151015
$secondItem->getSelectionId(),
10161016
];
1017-
if ($aPosition == $bPosition) {
1018-
return 0;
1019-
}
1020-
return $aPosition < $bPosition ? -1 : 1;
1017+
1018+
return $aPosition <=> $bPosition;
10211019
}
10221020

10231021
/**

app/code/Magento/Config/Model/Config/Structure/Mapper/Sorting.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,6 @@ protected function _cmp($elementA, $elementB)
6262
$sortIndexB = (float)$elementB['sortOrder'];
6363
}
6464

65-
if ($sortIndexA == $sortIndexB) {
66-
return 0;
67-
}
68-
69-
return $sortIndexA < $sortIndexB ? -1 : 1;
65+
return $sortIndexA <=> $sortIndexB;
7066
}
7167
}

app/code/Magento/Deploy/Model/DeploymentConfig/ImporterPool.php

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -187,14 +187,7 @@ public function getValidator($section)
187187
private function sort(array $data)
188188
{
189189
uasort($data, function (array $a, array $b) {
190-
$a['sort_order'] = $this->getSortOrder($a);
191-
$b['sort_order'] = $this->getSortOrder($b);
192-
193-
if ($a['sort_order'] == $b['sort_order']) {
194-
return 0;
195-
}
196-
197-
return ($a['sort_order'] < $b['sort_order']) ? -1 : 1;
190+
return $this->getSortOrder($a) <=> $this->getSortOrder($b);
198191
});
199192

200193
return $data;

app/code/Magento/Paypal/Model/Express/Checkout.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1056,10 +1056,7 @@ protected function _prepareShippingOptions(Address $address, $mayReturnEmpty = f
10561056
*/
10571057
protected static function cmpShippingOptions(DataObject $option1, DataObject $option2)
10581058
{
1059-
if ($option1->getAmount() == $option2->getAmount()) {
1060-
return 0;
1061-
}
1062-
return ($option1->getAmount() < $option2->getAmount()) ? -1 : 1;
1059+
return $option1->getAmount() <=> $option2->getAmount();
10631060
}
10641061

10651062
/**

app/code/Magento/Sales/Block/Adminhtml/Order/View/Tab/History.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -303,11 +303,7 @@ public static function sortHistoryByTimestamp($a, $b)
303303
$createdAtA = $a['created_at'];
304304
$createdAtB = $b['created_at'];
305305

306-
/** @var $createdAtA \DateTime */
307-
if ($createdAtA->getTimestamp() == $createdAtB->getTimestamp()) {
308-
return 0;
309-
}
310-
return $createdAtA->getTimestamp() < $createdAtB->getTimestamp() ? -1 : 1;
306+
return $createdAtA->getTimestamp() <=> $createdAtB->getTimestamp();
311307
}
312308

313309
/**

app/code/Magento/Sales/Model/Order/Pdf/AbstractPdf.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -641,11 +641,7 @@ protected function _sortTotalsList($a, $b)
641641
return 0;
642642
}
643643

644-
if ($a['sort_order'] == $b['sort_order']) {
645-
return 0;
646-
}
647-
648-
return $a['sort_order'] > $b['sort_order'] ? 1 : -1;
644+
return $a['sort_order'] <=> $b['sort_order'];
649645
}
650646

651647
/**

app/code/Magento/Ui/DataProvider/Modifier/Pool.php

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -88,14 +88,7 @@ public function getModifiersInstances()
8888
protected function sort(array $data)
8989
{
9090
usort($data, function (array $a, array $b) {
91-
$a['sortOrder'] = $this->getSortOrder($a);
92-
$b['sortOrder'] = $this->getSortOrder($b);
93-
94-
if ($a['sortOrder'] == $b['sortOrder']) {
95-
return 0;
96-
}
97-
98-
return ($a['sortOrder'] < $b['sortOrder']) ? -1 : 1;
91+
return $this->getSortOrder($a) <=> $this->getSortOrder($b);
9992
});
10093

10194
return $data;

dev/tests/functional/tests/app/Magento/Downloadable/Test/Constraint/AssertDownloadableDuplicateForm.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,7 @@ protected function sortDownloadableArray(array $fields)
3232
usort(
3333
$fields,
3434
function ($row1, $row2) {
35-
if ($row1['sort_order'] == $row2['sort_order']) {
36-
return 0;
37-
}
38-
39-
return ($row1['sort_order'] < $row2['sort_order']) ? -1 : 1;
35+
return $row1['sort_order'] <=> $row2['sort_order'];
4036
}
4137
);
4238

lib/internal/Magento/Framework/Communication/Config/CompositeReader.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,10 @@ public function __construct(array $readers)
2727
usort(
2828
$readers,
2929
function ($firstItem, $secondItem) {
30-
if (!isset($firstItem['sortOrder']) || !isset($secondItem['sortOrder'])
31-
|| $firstItem['sortOrder'] == $secondItem['sortOrder']
32-
) {
30+
if (!isset($firstItem['sortOrder']) || !isset($secondItem['sortOrder'])) {
3331
return 0;
3432
}
35-
return $firstItem['sortOrder'] < $secondItem['sortOrder'] ? -1 : 1;
33+
return $firstItem['sortOrder'] <=> $secondItem['sortOrder'];
3634
}
3735
);
3836
$this->readers = [];

0 commit comments

Comments
 (0)