Completed
Push — master ( 390c77...fb089c )
by Mahmoud
03:19
created

ConfigsLoaderTrait::autoLoadConfigFiles()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 5
rs 9.4285
cc 1
eloc 3
nc 1
nop 0
1
<?php
2
3
namespace App\Port\Config\Loaders;
4
5
use App;
6
use App\Port\Butler\Portals\Facade\PortButler;
7
use DB;
8
use File;
9
use Log;
10
11
/**
12
 * Class ConfigsLoaderTrait.
13
 *
14
 * @author  Mahmoud Zalt <[email protected]>
15
 */
16
trait ConfigsLoaderTrait
17
{
18
19
    /**
20
     * Auto load Containers and Port config files into Laravel
21
     */
22
    public function autoLoadConfigFiles()
23
    {
24
        $this->autoLoadContainersConfigFiles();
25
        $this->autoLoadPortConfigFiles();
26
    }
27
28
    protected function autoLoadContainersConfigFiles()
29
    {
30
        foreach (PortButler::getContainersNames() as $containerName) {
31
            $this->loadConfigs(base_path('app/Containers/' . $containerName . '/Configs'));
32
        }
33
    }
34
35
    protected function autoLoadPortConfigFiles()
36
    {
37
        $this->loadConfigs(base_path('app/Port/Config/Configs'));
38
    }
39
40
    /**
41
     * @param $directory
42
     */
43
    private function loadConfigs($directory)
44
    {
45
        if (File::isDirectory($directory)) {
46
47
            $files = File::allFiles($directory);
48
49
            foreach ($files as $file) {
50
                // build the key from the file name (just remove the .php extension from the file name)
51
                $fileNameOnly = str_replace('.php', '', $file->getFilename());
52
53
                // merge the config file
54
                $this->mergeConfigFrom($file->getPathname(), $fileNameOnly);
0 ignored issues
show
Bug introduced by
It seems like mergeConfigFrom() 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...
55
            }
56
        }
57
    }
58
}
59