Completed
Push — master ( 60840d...857394 )
by Mahmoud
03:05
created

loadProvidersFromContainers()   B

Complexity

Conditions 6
Paths 6

Size

Total Lines 27
Code Lines 11

Duplication

Lines 27
Ratio 100 %

Importance

Changes 0
Metric Value
dl 27
loc 27
rs 8.439
c 0
b 0
f 0
cc 6
eloc 11
nc 6
nop 0
1
<?php
2
3
namespace App\Port\Loader\Loaders;
4
5
use App;
6
use App\Port\Foundation\Portals\Facade\PortButler;
7
use DB;
8
use File;
9
use Log;
10
11
/**
12
 * Class ProvidersLoaderTrait.
13
 *
14
 * @author  Mahmoud Zalt <[email protected]>
15
 */
16
trait ProvidersLoaderTrait
17
{
18
19
    /**
20
     * runProvidersAutoLoader
21
     */
22
    public function runProvidersAutoLoader()
23
    {
24
        $this->loadProvidersFromPort();
25
        $this->loadProvidersFromContainers();
26
    }
27
28
    /**
29
     * loadProvidersFromContainers
30
     */
31 View Code Duplication
    private function loadProvidersFromContainers()
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...
32
    {
33
        $mainServiceProviderNameStartWith = 'Main';
34
35
        foreach (PortButler::getContainersNames() as $containerName) {
36
37
            $containerProvidersDirectory = base_path('app/Containers/' . $containerName . '/Providers');
38
39
            if (File::isDirectory($containerProvidersDirectory)) {
40
41
                $files = \File::allFiles($containerProvidersDirectory);
42
43
                foreach ($files as $file) {
44
45
                    if (\File::isFile($file)) {
46
47
                        // Check if this is the Main Service Provider
48
                        if (PortButler::stringStartsWith($file->getFilename(), $mainServiceProviderNameStartWith)) {
49
                            $serviceProviderClass = PortButler::getClassFullNameFromFile($file->getPathname());
50
51
                            $this->loadProvider($serviceProviderClass);
52
                        }
53
                    }
54
                }
55
            }
56
        }
57
    }
58
59
    /**
60
     * loadProvidersFromPort
61
     */
62
    private function loadProvidersFromPort()
63
    {
64
        foreach ($this->serviceProviders as $providerClass) {
0 ignored issues
show
Bug introduced by
The property serviceProviders 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...
65
            $this->loadProvider($providerClass);
66
        }
67
    }
68
69
    /*
70
     * loadProvider
71
     */
72
    private function loadProvider($provider)
73
    {
74
        App::register($provider);
75
    }
76
77
    /**
78
     * loadContainersInternalProviders
79
     */
80
    public function loadContainersInternalProviders()
81
    {
82
        foreach ($this->containerServiceProviders as $provider) {
0 ignored issues
show
Bug introduced by
The property containerServiceProviders does not seem to exist. Did you mean serviceProviders?

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...
83
            $this->loadProvider($provider);
84
        }
85
    }
86
}
87