Skip to content

Commit d4e92fc

Browse files
author
Stanislav Idolov
authored
ENGCOM-2641: [Forwardport] Replace sort callbacks to spaceship operator #17330
2 parents b6c47a2 + f8d086f commit d4e92fc

File tree

4 files changed

+5
-28
lines changed

4 files changed

+5
-28
lines changed

app/code/Magento/Catalog/Model/Product/Type/AbstractType.php

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -292,13 +292,7 @@ public function attributesCompare($attributeOne, $attributeTwo)
292292
$sortOne = $attributeOne->getGroupSortPath() * 1000 + $attributeOne->getSortPath() * 0.0001;
293293
$sortTwo = $attributeTwo->getGroupSortPath() * 1000 + $attributeTwo->getSortPath() * 0.0001;
294294

295-
if ($sortOne > $sortTwo) {
296-
return 1;
297-
} elseif ($sortOne < $sortTwo) {
298-
return -1;
299-
}
300-
301-
return 0;
295+
return $sortOne <=> $sortTwo;
302296
}
303297

304298
/**

app/code/Magento/Eav/Model/Entity/AbstractEntity.php

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -591,13 +591,7 @@ public function attributesCompare($firstAttribute, $secondAttribute)
591591
$firstSort = $firstAttribute->getSortWeight((int) $this->_sortingSetId);
592592
$secondSort = $secondAttribute->getSortWeight((int) $this->_sortingSetId);
593593

594-
if ($firstSort > $secondSort) {
595-
return 1;
596-
} elseif ($firstSort < $secondSort) {
597-
return -1;
598-
}
599-
600-
return 0;
594+
return $firstSort <=> $secondSort;
601595
}
602596

603597
/**

app/code/Magento/Quote/Model/Quote/Address.php

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -872,13 +872,7 @@ public function getGroupedAllShippingRates()
872872
*/
873873
protected function _sortRates($firstItem, $secondItem)
874874
{
875-
if ((int)$firstItem[0]->carrier_sort_order < (int)$secondItem[0]->carrier_sort_order) {
876-
return -1;
877-
} elseif ((int)$firstItem[0]->carrier_sort_order > (int)$secondItem[0]->carrier_sort_order) {
878-
return 1;
879-
} else {
880-
return 0;
881-
}
875+
return (int) $firstItem[0]->carrier_sort_order <=> (int) $secondItem[0]->carrier_sort_order;
882876
}
883877

884878
/**

app/code/Magento/Sales/Model/Config/Ordered.php

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -167,13 +167,8 @@ function ($a, $b) {
167167
if (!isset($a['sort_order']) || !isset($b['sort_order'])) {
168168
return 0;
169169
}
170-
if ($a['sort_order'] > $b['sort_order']) {
171-
return 1;
172-
} elseif ($a['sort_order'] < $b['sort_order']) {
173-
return -1;
174-
} else {
175-
return 0;
176-
}
170+
171+
return $a['sort_order'] <=> $b['sort_order'];
177172
}
178173
);
179174
}

0 commit comments

Comments
 (0)