Completed
Push — master ( 071bb7...06db50 )
by Mahmoud
03:08
created

SeederLoaderAbstract   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 80
Duplicated Lines 33.75 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 9
c 1
b 0
f 0
lcom 1
cbo 2
dl 27
loc 80
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A run() 0 5 1
B seedContainers() 26 26 5
A seedPort() 0 6 2
A seed() 0 4 1

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\Seeder\Loaders;
4
5
use App\Port\Foundation\Portals\Facade\PortButler;
6
use App\Port\Seeder\Testing\LiveTestingSeeder;
7
use Illuminate\Database\Seeder as LaravelSeeder;
8
9
/**
10
 * Class Seeder.
11
 *
12
 * @author  Mahmoud Zalt <[email protected]>
13
 */
14
abstract class SeederLoaderAbstract extends LaravelSeeder
15
{
16
17
    /**
18
     * Manually seeding some Port Seeders whenever needed
19
     *
20
     * @var  array
21
     */
22
    protected $portSeedersClasses = [
23
        LiveTestingSeeder::class,
24
    ];
25
26
    /**
27
     * Default seeders directory in the container
28
     *
29
     * @var  string
30
     */
31
    protected $seedersPath = '/Data/Seeders';
32
33
    /**
34
     * Run the database seeds.
35
     * Then Automatically register all Seeders from Containers.
36
     *
37
     * @return void
38
     */
39
    public function run()
40
    {
41
        $this->seedContainers();
42
        $this->seedPort();
43
    }
44
45
    /**
46
     *
47
     */
48 View Code Duplication
    private function seedContainers()
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...
49
    {
50
        foreach (PortButler::getContainersNames() as $containerName) {
51
52
            $containersDirectory = base_path('app/Containers/' . $containerName . $this->seedersPath);
53
54
            if (\File::isDirectory($containersDirectory)) {
55
56
                $files = \File::allFiles($containersDirectory);
57
58
                foreach ($files as $seederClass) {
59
60
                    if (\File::isFile($seederClass)) {
61
62
                        $pathName = $seederClass->getPathname();
63
64
                        $seederClass = PortButler::getClassFullNameFromFile($pathName);
65
66
                        $this->seed($seederClass);
67
                    }
68
69
                }
70
71
            }
72
        }
73
    }
74
75
    /**
76
     *
77
     */
78
    private function seedPort()
79
    {
80
        foreach ($this->portSeedersClasses as $seederClass) {
81
            $this->seed($seederClass);
82
        }
83
    }
84
85
    /**
86
     * @param $class
87
     */
88
    private function seed($class)
89
    {
90
        $this->call($class);
91
    }
92
93
}
94