Passed
Push — master ( d57c11...8c6e4f )
by Joao
03:16 queued 36s
created

MailerFactory::create()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 12
ccs 0
cts 9
cp 0
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 6
nc 2
nop 1
crap 6
1
<?php
2
/**
3
 * User: jg
4
 * Date: 28/05/17
5
 * Time: 11:50
6
 */
7
8
namespace ByJG\Mail;
9
10
use ByJG\Util\Uri;
11
12
class MailerFactory
13
{
14
    private static $config = [];
15
16
    public static function registerMailer($protocol, $class)
17
    {
18
        if (!class_exists($class, true)) {
19
            throw new \Exception('Class not found!');
20
        }
21
        self::$config[$protocol] = $class;
22
    }
23
24
    public static function create($connection)
25
    {
26
        $uri = new Uri($connection);
27
28
        if (!isset(self::$config[$uri->getScheme()])) {
29
            throw new \Exception('Protocol not found/registered!');
30
        }
31
32
        $class = self::$config[$uri->getScheme()];
33
34
        return new $class($uri);
35
    }
36
}
37