Completed
Pull Request — master (#96)
by
unknown
03:45
created

CanPublishConfiguration::getModuleConfigFilePath()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 4
rs 10
1
<?php
2
3
namespace Modules\Core\Traits;
4
5
trait CanPublishConfiguration
6
{
7
    /**
8
     * Publish the given configuration file name (without extension) and the given module
9
     * @param string $module
10
     * @param string $fileName
11
     */
12
    public function publishConfig($module, $fileName)
13
    {
14
        if (app()->environment() === 'testing') {
15
            return;
16
        }
17
        $this->mergeConfigFrom($this->getModuleConfigFilePath($module, $fileName), strtolower("asgard.$module.$fileName"));
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...
18
        $this->publishes([
0 ignored issues
show
Bug introduced by
It seems like publishes() 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...
19
            $this->getModuleConfigFilePath($module, $fileName) => config_path(strtolower("asgard.$module.$fileName")),
20
        ], 'config');
21
    }
22
23
    /**
24
     * Get path of the give file name in the given module
25
     * @param string $module
26
     * @param string $file
27
     * @return string
28
     */
29
    private function getModuleConfigFilePath($module, $file)
30
    {
31
        return $this->getModulePath($module) . "/Config/$file.php";
32
    }
33
34
    /**
35
     * @param $module
36
     * @return string
37
     */
38
    private function getModulePath($module)
39
    {
40
        return base_path('Modules' . DIRECTORY_SEPARATOR . ucfirst($module));
41
    }
42
}
43