Completed
Pull Request — master (#902)
by Andrej
02:38
created

MigrationsSorter   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 16
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 4
dl 0
loc 16
ccs 6
cts 6
cp 1
rs 10
c 1
b 0
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 2
A sort() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Doctrine\Migrations;
6
7
use Doctrine\Migrations\Metadata\AvailableMigration;
8
use function strcmp;
9
use function uasort;
10
11
/**
12
 * The MigrationsSorter class is responsible for sorting the migrations.
13
 *
14
 * @internal
15
 */
16
final class MigrationsSorter implements Sorter
17
{
18
    /** @var callable */
19
    private $sortFunc;
20
21 63
    public function __construct(?callable $sortFunc = null)
22
    {
23
        $this->sortFunc = $sortFunc ?: static function (AvailableMigration $m1, AvailableMigration $m2) {
24 32
            return strcmp((string) $m1->getVersion(), (string) $m2->getVersion());
25 63
        };
26 63
    }
27
28
    /** @param AvailableMigration[] $migrations */
29 56
    public function sort(array &$migrations) : void
30
    {
31 56
        uasort($migrations, $this->sortFunc);
32 56
    }
33
}
34