NotifierFactory::make()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
nc 3
nop 1
dl 0
loc 16
rs 9.7333
c 0
b 0
f 0
1
<?php
2
3
namespace Yoeunes\Notify;
4
5
use RuntimeException;
6
use Yoeunes\Notify\Notifiers\NotifierInterface;
7
8
class NotifierFactory
9
{
10
    /**
11
     * @param array $config
12
     *
13
     * @return NotifierInterface
14
     */
15
    public static function make(array $config): NotifierInterface
16
    {
17
        $driver = $config['default'];
18
19
        if (!isset($config[$driver])) {
20
            throw new RuntimeException('Unknown "'.$driver.'" notification driver.');
21
        }
22
23
        $class = $config[$driver]['class'];
24
25
        if (!class_exists($class)) {
26
            throw new RuntimeException('class "'.$class.'" does not exists.');
27
        }
28
29
        return new $class($config[$driver]);
30
    }
31
}
32