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

AliasesLoaderTrait   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 39
Duplicated Lines 46.15 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 9
lcom 1
cbo 1
dl 18
loc 39
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A loadShipInternalAliases() 9 9 4
A loadContainersInternalAliases() 9 9 4
A loadAlias() 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\Ship\Engine\Loaders;
4
5
use App;
6
use Illuminate\Foundation\AliasLoader;
7
8
/**
9
 * Class AliasesLoaderTrait.
10
 *
11
 * @author  Mahmoud Zalt <[email protected]>
12
 */
13
trait AliasesLoaderTrait
14
{
15
16
17
    /**
18
     * @param array $aliases
0 ignored issues
show
Bug introduced by
There is no parameter named $aliases. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
19
     */
20 View Code Duplication
    public function loadShipInternalAliases()
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...
21
    {
22
        // `$this->aliases` is declared on the Main Service Provider of the Ship layer
23
        foreach (isset($this->aliases) ? $this->aliases : [] as $aliasKey => $aliasValue) {
0 ignored issues
show
Bug introduced by
The property aliases does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
24
            if (class_exists($aliasValue)) {
25
                $this->loadAlias($aliasKey, $aliasValue);
26
            }
27
        }
28
    }
29
30
    /**
31
     * loadContainersInternalAliases
32
     */
33 View Code Duplication
    public function loadContainersInternalAliases()
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...
34
    {
35
        // `$this->aliases` is declared on each Container's Main Service Provider
36
        foreach (isset($this->containerAliases) ? $this->containerAliases : [] as $aliasKey => $aliasValue) {
0 ignored issues
show
Bug introduced by
The property containerAliases does not seem to exist. Did you mean aliases?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
37
            if (class_exists($aliasValue)) {
38
                $this->loadAlias($aliasKey, $aliasValue);
39
            }
40
        }
41
    }
42
43
    /**
44
     * @param $aliasKey
45
     * @param $aliasValue
46
     */
47
    private function loadAlias($aliasKey, $aliasValue)
48
    {
49
        AliasLoader::getInstance()->alias($aliasKey, $aliasValue);
50
    }
51
}
52