Completed
Push — master ( f8b6bf...bec27e )
by Mahmoud
03:02
created

AutoLoaderTrait::bootLoaders()   B

Complexity

Conditions 4
Paths 8

Size

Total Lines 25
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 25
rs 8.5806
cc 4
eloc 15
nc 8
nop 0
1
<?php
2
3
namespace App\Port\Loader;
4
5
use App\Port\Loader\Helpers\Facade\LoaderHelper;
6
use App\Port\Loader\Loaders\AliasesLoaderTrait;
7
use App\Port\Loader\Loaders\ConfigsLoaderTrait;
8
use App\Port\Loader\Loaders\ConsolesLoaderTrait;
9
use App\Port\Loader\Loaders\MigrationsLoaderTrait;
10
use App\Port\Loader\Loaders\ProvidersLoaderTrait;
11
use App\Port\Loader\Loaders\ViewsLoaderTrait;
12
13
/**
14
 * Class AutoLoaderTrait.
15
 *
16
 * @author  Mahmoud Zalt <[email protected]>
17
 */
18
trait AutoLoaderTrait
19
{
20
21
    // using each component loader trait
22
    use ConfigsLoaderTrait;
23
    use MigrationsLoaderTrait;
24
    use ViewsLoaderTrait;
25
    use ProvidersLoaderTrait;
26
    use ConsolesLoaderTrait;
27
    use AliasesLoaderTrait;
28
29
    /**
30
     * * to be used from the `boot` function of the main service provider
31
     */
32
    public function bootLoaders()
33
    {
34
        // the config files should be loaded first from all the directories in their own loop
35
        foreach (LoaderHelper::getPortFoldersNames() as $portFolderName) {
36
            $this->loadConfigsFromPort($portFolderName); // TODO: move this to the loop below at the top
37
        }
38
39
        // > iterate over all the port folders and autoload most of the components
40
        foreach (LoaderHelper::getPortFoldersNames() as $portFolderName) {
41
            $this->loadProvidersFromPort($portFolderName);
0 ignored issues
show
Unused Code introduced by
The call to AutoLoaderTrait::loadProvidersFromPort() has too many arguments starting with $portFolderName.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
42
            $this->loadMigrationsFromPort($portFolderName);
43
            $this->loadViewsFromPort($portFolderName);
44
            $this->loadConsolesFromPort($portFolderName);
45
        }
46
47
        // > iterate over all the containers folders and autoload most of the components
48
        foreach (LoaderHelper::getContainersNames() as $containerName) {
49
            $this->loadConfigsFromContainers($containerName);
50
            $this->loadProvidersFromContainers($containerName);
51
            $this->loadMigrationsFromContainers($containerName);
52
            $this->loadViewsFromContainers($containerName);
53
            $this->loadViewsFromContainers($containerName);
54
            $this->loadConsolesFromContainers($containerName);
55
        }
56
    }
57
58
    /**
59
     * to be used from the `register` function of the main service provider
60
     */
61
    public function registerLoaders()
62
    {
63
        $this->loadContainerFactories();
0 ignored issues
show
Bug introduced by
It seems like loadContainerFactories() 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...
64
        $this->loadPortInternalAliases();
65
    }
66
67
}
68