Skip to content

Commit 7dff85f

Browse files
authored
Merge pull request #23 from OpenClassrooms/chores/fix-deprecation-warning
Fix deprecation warning for usort
2 parents 0bb07b3 + 90dfe0d commit 7dff85f

1 file changed

Lines changed: 21 additions & 6 deletions

File tree

src/OpenClassrooms/UseCase/Application/Services/Proxy/UseCases/UseCaseProxy.php

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -179,8 +179,13 @@ private function sortPreStrategies()
179179
usort(
180180
$this->strategies,
181181
function (ProxyStrategyBag $s1, ProxyStrategyBag $s2) {
182-
return array_search($s1->getType(), UseCaseProxy::$strategyPreOrder) >
183-
array_search($s2->getType(), UseCaseProxy::$strategyPreOrder);
182+
$pos1 = array_search($s1->getType(), UseCaseProxy::$strategyPreOrder);
183+
$pos2 = array_search($s2->getType(), UseCaseProxy::$strategyPreOrder);
184+
185+
$pos1 = (false === $pos1) ? PHP_INT_MAX : $pos1;
186+
$pos2 = (false === $pos2) ? PHP_INT_MAX : $pos2;
187+
188+
return $pos1 <=> $pos2;
184189
}
185190
);
186191
}
@@ -215,8 +220,13 @@ private function sortPostStrategies()
215220
usort(
216221
$this->strategies,
217222
function (ProxyStrategyBag $s1, ProxyStrategyBag $s2) {
218-
return array_search($s1->getType(), UseCaseProxy::$strategyPostOrder) >
219-
array_search($s2->getType(), UseCaseProxy::$strategyPostOrder);
223+
$pos1 = array_search($s1->getType(), UseCaseProxy::$strategyPostOrder);
224+
$pos2 = array_search($s2->getType(), UseCaseProxy::$strategyPostOrder);
225+
226+
$pos1 = (false === $pos1) ? PHP_INT_MAX : $pos1;
227+
$pos2 = (false === $pos2) ? PHP_INT_MAX : $pos2;
228+
229+
return $pos1 <=> $pos2;
220230
}
221231
);
222232
}
@@ -242,8 +252,13 @@ private function sortOnExceptionStrategies()
242252
usort(
243253
$this->strategies,
244254
function (ProxyStrategyBag $s1, ProxyStrategyBag $s2) {
245-
return array_search($s1->getType(), UseCaseProxy::$strategyOnExceptionOrder) >
246-
array_search($s2->getType(), UseCaseProxy::$strategyOnExceptionOrder);
255+
$pos1 = array_search($s1->getType(), UseCaseProxy::$strategyOnExceptionOrder);
256+
$pos2 = array_search($s2->getType(), UseCaseProxy::$strategyOnExceptionOrder);
257+
258+
$pos1 = (false === $pos1) ? PHP_INT_MAX : $pos1;
259+
$pos2 = (false === $pos2) ? PHP_INT_MAX : $pos2;
260+
261+
return $pos1 <=> $pos2;
247262
}
248263
);
249264
}

0 commit comments

Comments
 (0)