Migrator   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 9
c 1
b 0
f 0
dl 0
loc 30
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getMigrationFiles() 0 9 2
A findMigrationFiles() 0 3 1
1
<?php
2
3
namespace TestMonitor\NestedMigrations\Migrations;
4
5
use Illuminate\Support\Str;
6
use Illuminate\Support\Collection;
7
use Illuminate\Database\Migrations\Migrator as IlluminateMigrator;
8
9
class Migrator extends IlluminateMigrator
10
{
11
    /**
12
     * Get all of the migration files in a given path, including
13
     * those in a nested folder.
14
     *
15
     * @param  string|array  $paths
16
     * @return array
17
     */
18
    public function getMigrationFiles($paths)
19
    {
20
        return Collection::make($paths)->flatMap(function ($path) {
21
            return Str::endsWith($path, '.php') ? [$path] : $this->findMigrationFiles($path);
22
        })->filter()->values()->keyBy(function ($file) {
23
            return $this->getMigrationName($file);
24
        })->sortBy(function ($file, $key) {
25
            return $key;
26
        })->all();
27
    }
28
29
    /**
30
     * Finds migration files recursively, limited to one level.
31
     *
32
     * @param string $path
33
     *
34
     * @return array
35
     */
36
    protected function findMigrationFiles($path)
37
    {
38
        return $this->files->glob($path . '/{,*/}*_*.php', GLOB_BRACE);
39
    }
40
}
41