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

FixtureSorter   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 8
lcom 0
cbo 1
dl 0
loc 27
ccs 12
cts 12
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A sort() 0 5 1
B orderedFixtureSorter() 0 18 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