Completed
Push — master ( dc322e...438d0e )
by Mahmoud
03:27
created

ConsolesLoaderTrait   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 46
Duplicated Lines 30.43 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 1
dl 14
loc 46
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A loadConsolesFromContainers() 0 6 1
A loadConsolesFromShip() 0 6 1
A loadTheConsoles() 14 17 3

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\Ship\Engine\Loaders;
4
5
use App;
6
use App\Ship\Engine\Butlers\Facades\LoaderButler;
7
use File;
8
9
/**
10
 * Class ConsolesLoaderTrait.
11
 *
12
 * @author  Mahmoud Zalt <[email protected]>
13
 */
14
trait ConsolesLoaderTrait
15
{
16
17
    /**
18
     * @param $containerName
19
     */
20
    public function loadConsolesFromContainers($containerName)
21
    {
22
        $containerCommandsDirectory = base_path('app/Containers/' . $containerName . '/UI/CLI/Commands/');
23
24
        $this->loadTheConsoles($containerCommandsDirectory);
25
    }
26
27
    /**
28
     * @param $portFolderName
29
     */
30
    public function loadConsolesFromShip($portFolderName)
0 ignored issues
show
Unused Code introduced by
The parameter $portFolderName is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
31
    {
32
//        $portFolderName = base_path('app/Ship/') . $portFolderName . '/Commands/';
0 ignored issues
show
Unused Code Comprehensibility introduced by
47% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
33
//
34
//        $this->loadTheConsoles($portFolderName);
35
    }
36
37
    /**
38
     * @param $consoleClass
39
     */
40
    private function loadTheConsoles($directory)
41
    {
42 View Code Duplication
        if (File::isDirectory($directory)) {
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...
43
44
            $files = File::allFiles($directory);
45
46
            foreach ($files as $consoleFile) {
47
48
                $consoleClass = LoaderButler::getClassFullNameFromFile($consoleFile->getPathname());
49
50
                // when user from the Main Service Provider, which extends Laravel
51
                // service provider you get access to `$this->commands`
52
                $this->commands([$consoleClass]);
0 ignored issues
show
Bug introduced by
It seems like commands() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
53
            }
54
55
        }
56
    }
57
58
59
}
60