Passed
Branch develop (1ecfd6)
by Nuno
02:37
created

Migrator::getMigrationFiles()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 30

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 30
ccs 0
cts 20
cp 0
rs 9.44
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 2
1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * This file is part of Laravel Zero.
7
 *
8
 * (c) Nuno Maduro <[email protected]>
9
 *
10
 *  For the full copyright and license information, please view the LICENSE
11
 *  file that was distributed with this source code.
12
 */
13
14
namespace LaravelZero\Framework\Components\Database;
15
16
use function collect;
17
use Symfony\Component\Finder\Finder;
18
use Illuminate\Database\Migrations\Migrator as BaseMigrator;
19
20
class Migrator extends BaseMigrator
21
{
22
    /**
23
     * Get all of the migration files in a given path.
24
     *
25
     * Differs from the original `getMigrationFiles` because
26
     * the phar don't support globs.
27
     *
28
     * @param  string|array $paths
29
     *
30
     * @return array
31
     */
32
    public function getMigrationFiles($paths): array
33
    {
34
        return collect($paths)
35
            ->flatMap(
36
                function ($path) {
37
                    return collect(
38
                        (new Finder)->in([$path])
39
                            ->files()
40
                    )
41
                        ->map(
42
                            function ($file) {
43
                                return $file->getPathname();
44
                            }
45
                        )
46
                        ->all();
47
                }
48
            )
49
            ->filter()
50
            ->sortBy(
51
                function ($file) {
52
                    return $this->getMigrationName($file);
53
                }
54
            )
55
            ->values()
56
            ->keyBy(
57
                function ($file) {
58
                    return $this->getMigrationName($file);
59
                }
60
            )
61
            ->all();
62
    }
63
}
64