Completed
Push — master ( 4ab2af...3c144f )
by Mark
9s
created

Migrator::getFilePathWithoutFolders()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 5
Bugs 3 Features 1
Metric Value
c 5
b 3
f 1
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
namespace Jaybizzle\MigrationsOrganiser;
4
5
use Illuminate\Database\Migrations\Migrator as M;
6
use RecursiveIteratorIterator as Iterator;
7
use RecursiveDirectoryIterator as DirectoryIterator;
8
9
class Migrator extends M
10
{
11
12
    /**
13
     * Get all of the migration files in a given path.
14
     *
15
     * @param string $path
0 ignored issues
show
Bug introduced by
There is no parameter named $path. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
16
     * @param bool   $recursive
17
     *
18
     * @return array
19
     */
20
    public function getMigrationFiles($paths = [], $recursive = true)
21
    {
22
        if ($recursive) {
23
            $paths = $this->getRecursiveFolders($paths);
24
        }
25
26
        $files = parent::getMigrationFiles($paths);
27
28
        return $files;
29
    }
30
31
    /**
32
     * Get all subdirectories located in an array of folders
33
     *
34
     * @param array $folders
35
     *
36
     * @return array
37
     */
38
    public function getRecursiveFolders($folders)
39
    {
40
41
        $paths = [];
42
43
        foreach ($folders as $folder) {
44
            $iter = new Iterator(
45
                new DirectoryIterator($folder, DirectoryIterator::SKIP_DOTS),
46
                Iterator::SELF_FIRST,
47
                Iterator::CATCH_GET_CHILD // Ignore "Permission denied"
48
            );
49
50
            $subPaths = array($folder);
51
            foreach ($iter as $path => $dir) {
52
                if ($dir->isDir()) {
53
                    $subPaths[] = $path;
54
                }
55
            }
56
57
            $paths = array_merge($paths, $subPaths);
58
        }
59
60
        return $paths;
61
    }
62
63
    /**
64
     * Add date folders to migrations path.
65
     *
66
     * @param string $file
67
     *
68
     * @return string
69
     */
70
    public function getDateFolderStructure($file)
71
    {
72
        $parts = explode('_', $file);
73
74
        return $parts[0].'/'.$parts[1].'/';
75
    }
76
}
77