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

Migrator   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 1
dl 0
loc 42
ccs 0
cts 20
cp 0
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A getMigrationFiles() 0 30 1
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