Completed
Push — master ( 5c46bf...f77784 )
by Mahmoud
03:22
created

MigrationsLoaderTrait::loadMigrations()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 1
nop 1
1
<?php
2
3
namespace App\Port\Migration\Loaders;
4
5
use App;
6
use App\Port\Foundation\Portals\Facade\PortButler;
7
use DB;
8
use File;
9
10
/**
11
 * Class MigrationsLoaderTrait.
12
 *
13
 * @author  Mahmoud Zalt <[email protected]>
14
 */
15
trait MigrationsLoaderTrait
16
{
17
18
    protected $portMigrationsDirectories = [
19
        'Queue/Data/Migrations',
20
    ];
21
22
    public function runMigrationsAutoLoader()
23
    {
24
        $this->loadMigrationsFromContainers();
25
        $this->loadMigrationsFromPort();
26
    }
27
28 View Code Duplication
    private function loadMigrationsFromContainers()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
29
    {
30
        foreach (PortButler::getContainersNames() as $containerName) {
31
32
            $containerMigrationDirectory = base_path('app/Containers/' . $containerName . '/Data/Migrations');
33
34
            if (File::isDirectory($containerMigrationDirectory)) {
35
36
                $this->loadMigrations($containerMigrationDirectory);
37
38
            }
39
        }
40
    }
41
42
    private function loadMigrationsFromPort()
43
    {
44
        foreach ($this->portMigrationsDirectories as $portMigrationsDirectory) {
45
            $this->loadMigrations($portMigrationsDirectory);
46
        }
47
48
    }
49
50
    private function loadMigrations($directory)
51
    {
52
        App::afterResolving('migrator', function ($migrator) use ($directory) {
53
            foreach ((array)$directory as $path) {
54
                $migrator->path($path);
55
            }
56
        });
57
    }
58
59
}
60