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

MigrationsSorter::__construct()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 2
nc 1
nop 1
dl 0
loc 4
ccs 2
cts 2
cp 1
crap 2
rs 10
c 1
b 0
f 0
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