Completed
Push — master ( bec27e...637f9e )
by Mahmoud
03:05
created

SeederLoaderAbstract::loadSeeds()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 21
Code Lines 7

Duplication

Lines 21
Ratio 100 %

Importance

Changes 0
Metric Value
dl 21
loc 21
rs 9.0534
c 0
b 0
f 0
cc 4
eloc 7
nc 4
nop 1
1
<?php
2
3
namespace App\Port\Loader\Loaders;
4
5
use App\Port\Loader\Helpers\Facade\LoaderHelper;
6
use Illuminate\Database\Seeder as LaravelSeeder;
7
8
/**
9
 * Class Seeder.
10
 *
11
 * This Class has inverted dependency :( you must extend this class from the default
12
 * seeder class provided by the framework (database/seeds/DatabaseSeeder.php)
13
 *
14
 * @author  Mahmoud Zalt <[email protected]>
15
 */
16
abstract class SeederLoaderAbstract extends LaravelSeeder
17
{
18
19
    /**
20
     * Default seeders directory for containers and port
21
     *
22
     * @var  string
23
     */
24
    protected $seedersPath = '/Data/Seeders';
25
26
    /**
27
     * Run the database seeds.
28
     * Then Automatically register all Seeders from Containers.
29
     *
30
     * @return void
31
     */
32
    public function run()
33
    {
34
        $this->loadSeedersFromContainers();
35
        $this->loadSeedersFromPort();
36
    }
37
38
    /**
39
     * loadSeedersFromContainers
40
     */
41 View Code Duplication
    private function loadSeedersFromContainers()
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...
42
    {
43
        foreach (LoaderHelper::getContainersNames() as $containerName) {
44
45
            $containersDirectory = base_path('app/Containers/' . $containerName . $this->seedersPath);
46
47
            $this->loadSeeds($containersDirectory);
48
        }
49
    }
50
51
    /**
52
     *
53
     */
54 View Code Duplication
    private function loadSeedersFromPort()
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...
55
    {
56
        // it has to do it's own loop for now
57
        foreach (LoaderHelper::getPortFoldersNames() as $portFolderName) {
58
59
            $portSeedersDirectory = base_path('app/Port/') . $portFolderName . $this->seedersPath;
60
61
            $this->loadSeeds($portSeedersDirectory);
62
        }
63
64
    }
65
66
    /**
67
     * @param $directory
68
     */
69 View Code Duplication
    private function loadSeeds($directory)
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...
70
    {
71
        if (\File::isDirectory($directory)) {
72
73
            $files = \File::allFiles($directory);
74
75
            foreach ($files as $seederClass) {
76
77
                if (\File::isFile($seederClass)) {
78
79
                    $seederClass = LoaderHelper::getClassFullNameFromFile($seederClass->getPathname());
80
81
                    // seed it
82
                    $this->call($seederClass);
83
                }
84
85
            }
86
87
        }
88
89
    }
90
91
}
92