Completed
Pull Request — master (#14)
by
unknown
03:13
created

Migrator::getRecursiveFolders()   B

Complexity

Conditions 4
Paths 4

Size

Total Lines 24
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
dl 0
loc 24
rs 8.6845
c 1
b 1
f 0
cc 4
eloc 13
nc 4
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
     * Fully qualified path to the application's migration directory
13
     *
14
     * @var string
15
     */
16
    private $path;
0 ignored issues
show
Unused Code introduced by
The property $path is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

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