Completed
Push — master ( de0157...a1b6f9 )
by Lucas Pires
03:51
created

Driver::getConfigPath()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 12
rs 9.4285
cc 2
eloc 7
nc 2
nop 0
1
<?php
2
3
namespace FlyingLuscas\BugNotifier\Drivers;
4
5
use FlyingLuscas\BugNotifier\Exceptions\DriverConfigPathNotFoundException;
6
7
abstract class Driver
8
{
9
    /**
10
     * Get the driver configurations.
11
     *
12
     * @param  string $name
13
     *
14
     * @return mixed
15
     */
16
    protected function config($name = null)
17
    {
18
        if (is_null($name)) {
19
            return config($this->getConfigPath());
20
        }
21
22
        return config(sprintf('%s.%s', $this->getConfigPath(), $name));
23
    }
24
25
    /**
26
     * Get the driver configuration path.
27
     *
28
     * @return string|null
29
     */
30
    private function getConfigPath()
31
    {
32
        $classname = class_basename(get_called_class());
33
        $config = strtolower(preg_replace('/driver$/i', null, $classname));
34
        $path = sprintf('bugnotifier.%s', $config);
35
36
        if (config($path, false) === false) {
37
            throw new DriverConfigPathNotFoundException;
38
        }
39
40
        return $path;
41
    }
42
}
43