Passed
Branch master (f36b3c)
by Matthew
08:01
created

Factory::create()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 13
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 4

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 9
c 1
b 0
f 0
dl 0
loc 13
ccs 9
cts 9
cp 1
rs 9.9666
cc 4
nc 4
nop 1
crap 4
1
<?php
2
namespace Fyuze\Database\Drivers;
3
4
use InvalidArgumentException;
5
6
class Factory
7
{
8
    /**
9
     * @param array $config
10
     * @return Mysql|Sqlite
11
     * @throws InvalidArgumentException
12
     */
13 10
    public static function create($config)
14
    {
15 10
        if(!array_key_exists('driver', $config)) {
16 1
            throw new InvalidArgumentException('You must specify a driver');
17
        }
18
19 9
        switch ($config['driver']) {
20 9
            case 'mysql':
21 1
                return new Mysql($config);
22 8
            case 'sqlite':
23 7
                return new Sqlite($config);
24
            default:
25 1
                throw new InvalidArgumentException('Invalid or no driver specified');
26
        }
27
    }
28
}
29