Skip to content

Commit 9e6d4b5

Browse files
committed
Additional usort callback replacements with spaceship operator
1 parent 29d486e commit 9e6d4b5

File tree

3 files changed

+4
-21
lines changed

3 files changed

+4
-21
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
@@ -291,13 +291,7 @@ public function attributesCompare($attributeOne, $attributeTwo)
291291
$sortOne = $attributeOne->getGroupSortPath() * 1000 + $attributeOne->getSortPath() * 0.0001;
292292
$sortTwo = $attributeTwo->getGroupSortPath() * 1000 + $attributeTwo->getSortPath() * 0.0001;
293293

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

303297
/**

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

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

605-
if ($firstSort > $secondSort) {
606-
return 1;
607-
} elseif ($firstSort < $secondSort) {
608-
return -1;
609-
}
610-
611-
return 0;
605+
return $firstSort <=> $secondSort;
612606
}
613607

614608
/**

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)