Completed
Push — master ( 629b98...606f80 )
by Brian
11:50
created

MigrationPublisher::getSource()   B

Complexity

Conditions 5
Paths 5

Size

Total Lines 32
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 30

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 32
ccs 0
cts 19
cp 0
rs 8.439
cc 5
eloc 15
nc 5
nop 1
crap 30
1
<?php
2
3
/*
4
 * This file is part of Laravel Service Provider.
5
 *
6
 * (c) DraperStudio <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace DraperStudio\ServiceProvider\Publisher;
13
14
class MigrationPublisher extends Publisher
15
{
16
    /**
17
     * Get the source assets directory to publish.
18
     *
19
     * @param string $packagePath
20
     *
21
     * @return string
22
     *
23
     * @throws \InvalidArgumentException
24
     */
25
    protected function getSource($packagePath)
26
    {
27
        $sources = [
28
            "{$packagePath}/resources/database/migrations",
29
            "{$packagePath}/resources/migrations",
30
            "{$packagePath}/migrations",
31
        ];
32
33
        // iterate through all possible locations
34
        foreach ($sources as $source) {
35
            if ($this->files->isDirectory($source)) {
36
                $paths = [];
37
38
                // get all files of the current directory
39
                $files = $this->getSourceFiles($source);
40
41
                // iterate through all files
42
                foreach ($files as $file) {
43
                    // if the destination doesn't exist we can add the file to the queue
44
                    if (!class_exists($this->getClassFromFile($file))) {
45
                        $paths[$file] = $this->getDestinationPath('migrations', [
46
                            date('Y_m_d_His', time()), $this->getFileName($file),
47
                        ]);
48
                    }
49
                }
50
51
                return $paths;
52
            }
53
        }
54
55
        throw new InvalidArgumentException('Migrations not found.');
56
    }
57
}
58