Completed
Pull Request — master (#72)
by Ilario
09:34 queued 07:54
created

FixtureSorter::orderedFixtureSorter()   B

Complexity

Conditions 7
Paths 1

Size

Total Lines 18

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 7

Importance

Changes 0
Metric Value
dl 0
loc 18
ccs 9
cts 9
cp 1
rs 8.8333
c 0
b 0
f 0
cc 7
nc 1
nop 0
crap 7
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