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

ConfigsLoaderTrait::loadConfigsFromContainers()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 6
rs 9.4285
cc 1
eloc 3
nc 1
nop 1
1
<?php
2
3
namespace App\Port\Loader\Loaders;
4
5
use App;
6
use DB;
7
use File;
8
9
/**
10
 * Class ConfigsLoaderTrait.
11
 *
12
 * @author  Mahmoud Zalt <[email protected]>
13
 */
14
trait ConfigsLoaderTrait
15
{
16
17
    /**
18
     * @param $containerName
19
     */
20
    public function loadConfigsFromContainers($containerName)
21
    {
22
        $containerConfigsDirectory = base_path('app/Containers/' . $containerName . '/Configs');
23
24
        $this->loadConfigs($containerConfigsDirectory);
25
    }
26
27
    /**
28
     * @param $portFolderName
29
     */
30
    public function loadConfigsFromPort($portFolderName)
31
    {
32
        // $this->portConfigsDirectories is defined on the main service provider class
33
34
        $portConfigsDirectory = base_path('app/Port/') . $portFolderName . '/Configs';
35
36
        $this->loadConfigs($portConfigsDirectory);
37
    }
38
39
    /**
40
     * @param $directory
41
     */
42
    private function loadConfigs($directory)
43
    {
44
        if (File::isDirectory($directory)) {
45
46
            $files = File::allFiles($directory);
47
48
            foreach ($files as $file) {
49
                // build the key from the file name (just remove the .php extension from the file name)
50
                $fileNameOnly = str_replace('.php', '', $file->getFilename());
51
52
                // merge the config file
53
                $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...
54
            }
55
        }
56
    }
57
}
58