ConsolesLoaderTrait::loadTheConsoles()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 17
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 17
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 6
nc 3
nop 1
1
<?php
2
3
namespace App\Ship\Engine\Loaders;
4
5
use App;
6
use App\Ship\Engine\Butlers\Facades\ShipButler;
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
        if (File::isDirectory($directory)) {
43
44
            $files = File::allFiles($directory);
45
46
            foreach ($files as $consoleFile) {
47
48
                $consoleClass = ShipButler::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