Driver::getConfigPath()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2.0116

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 12
ccs 6
cts 7
cp 0.8571
rs 9.4285
cc 2
eloc 7
nc 2
nop 0
crap 2.0116
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
     * @param  mixed  $default
14
     *
15
     * @return mixed
16
     */
17 6
    protected function config($name = null, $default = null)
18
    {
19 6
        if (is_null($name)) {
20
            return config($this->getConfigPath(), $default);
21
        }
22
23 6
        return config(sprintf('%s.%s', $this->getConfigPath(), $name), $default);
24
    }
25
26
    /**
27
     * Get the driver configuration path.
28
     *
29
     * @return string|null
30
     */
31 6
    private function getConfigPath()
32
    {
33 6
        $classname = class_basename(get_called_class());
34 6
        $config = strtolower(preg_replace('/driver$/i', null, $classname));
35 6
        $path = sprintf('bugnotifier.%s', $config);
36
37 6
        if (config($path, false) === false) {
38
            throw new DriverConfigPathNotFoundException;
39
        }
40
41 6
        return $path;
42
    }
43
}
44