Skip to content

Commit

Permalink
Fix obviously wrong usort
Browse files Browse the repository at this point in the history
  • Loading branch information
ciaranmcnulty committed Sep 24, 2020
1 parent 2f50454 commit 1e9fd18
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions src/Prophecy/Prophecy/MethodProphecy.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,30 @@ function(ReflectionType $type) { return $type->getName(); },

usort(
$types,
function(string $type) {
if(class_exists($type) || interface_exists($type)) {
static function(string $type1, string $type2) {

// null is lowest priority
if ($type2 == 'null') {
return -1;
}
elseif ($type1 == 'null') {
return 1;
}

// objects are higher priority than scalars
$isObject = static function($type) {
return class_exists($type) || interface_exists($type);
};

if($isObject($type1) && !$isObject($type2)) {
return -1;
}
if ($type == 'null') {
elseif(!$isObject($type1) && $isObject($type2))
{
return 1;
}

// don't sort both-scalars or both-objects
return 0;
}
);
Expand Down

0 comments on commit 1e9fd18

Please sign in to comment.