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

MigrationsLoaderTrait   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 45
Duplicated Lines 28.89 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 1
dl 13
loc 45
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A runMigrationsAutoLoader() 0 5 1
A loadMigrationsFromContainers() 13 13 3
A loadMigrationsFromPort() 0 7 2
A loadMigrations() 0 8 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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