Migrator   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 1
eloc 19
c 1
b 0
f 0
dl 0
loc 38
rs 10

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 Illuminate\Database\Migrations\Migrator as BaseMigrator;
18
use SplFileInfo;
19
use Symfony\Component\Finder\Finder;
20
21
/**
22
 * @codeCoverageIgnore
23
 * @internal
24
 */
25
class Migrator extends BaseMigrator
26
{
27
    /**
28
     * Get all of the migration files in a given path.
29
     *
30
     * Differs from the original `getMigrationFiles` because
31
     * the phar don't support globs.
32
     */
33
    public function getMigrationFiles($paths): array
34
    {
35
        return collect($paths)
36
            ->flatMap(
37
                function ($path) {
38
                    return collect(
39
                        (new Finder)->in([$path])
40
                            ->files()
41
                    )
42
                        ->map(
43
                            function (SplFileInfo $file) {
44
                                return $file->getPathname();
45
                            }
46
                        )
47
                        ->all();
48
                }
49
            )
50
            ->filter()
51
            ->sortBy(
52
                function ($file) {
53
                    return $this->getMigrationName($file);
54
                }
55
            )
56
            ->values()
57
            ->keyBy(
58
                function ($file) {
59
                    return $this->getMigrationName($file);
60
                }
61
            )
62
            ->all();
63
    }
64
}
65