Completed
Pull Request — master (#72)
by Ilario
05:24
created

FixtureSorter::sort()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 5
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 1
1
<?php declare(strict_types=1);
2
3
namespace Facile\MongoDbBundle\Fixtures;
4
5
final class FixtureSorter
6
{
7 3
    public static function sort(array $fixtures): array
8
    {
9 3
        usort($fixtures, self::orderedFixtureSorter());
10 3
        return $fixtures;
11
    }
12
13
    private static function orderedFixtureSorter(): \Closure
14
    {
15 3
        return static function ($a, $b): int {
16 3
            if ($a instanceof OrderedFixtureInterface && $b instanceof OrderedFixtureInterface) {
17 3
                return $a->getOrder() - $b->getOrder();
18
            }
19
20 3
            if ($a instanceof OrderedFixtureInterface && ! $b instanceof OrderedFixtureInterface) {
21 3
                return 1;
22
            }
23
24 3
            if (! $a instanceof OrderedFixtureInterface && $b instanceof OrderedFixtureInterface) {
25 3
                return -1;
26
            }
27
28 3
            return 0;
29 3
        };
30
    }
31
}
32