Completed
Push — master ( d03d4d...9527ea )
by Mahmoud
02:48
created

SeederLoaderAbstract   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 45
Duplicated Lines 51.11 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
lcom 1
cbo 2
dl 23
loc 45
rs 10
c 1
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B run() 23 27 5

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\Butler\Portals\Facade\PortButler;
6
use Illuminate\Database\Seeder as LaravelSeeder;
7
8
/**
9
 * Class Seeder.
10
 *
11
 * @author  Mahmoud Zalt <[email protected]>
12
 */
13
abstract class SeederLoaderAbstract extends LaravelSeeder
14
{
15
16
    /**
17
     * Default seeders directory in the container
18
     *
19
     * @var  string
20
     */
21
    protected $seedersPath = '/Data/Seeders';
22
23
    /**
24
     * Run the database seeds.
25
     * Then Automatically register all Seeders from Containers.
26
     *
27
     * @return void
28
     */
29
    public function run()
30
    {
31
32 View Code Duplication
        foreach (PortButler::getContainersNames() as $containerName) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
33
34
            $containersDirectory = base_path('app/Containers/' . $containerName . $this->seedersPath);
35
36
            if (\File::isDirectory($containersDirectory)) {
37
38
                $files = \File::allFiles($containersDirectory);
39
40
                foreach ($files as $seederClass) {
41
42
                    if (\File::isFile($seederClass)) {
43
44
                        $pathName = $seederClass->getPathname();
45
46
                        $class = PortButler::getClassFullNameFromFile($pathName);
47
48
                        $this->call($class);
49
                    }
50
51
                }
52
53
            }
54
        }
55
    }
56
57
}
58