SimpleDBAL::factory()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 13
rs 9.8333
c 0
b 0
f 0
cc 3
nc 3
nop 3
1
<?php
2
3
namespace BenTools\SimpleDBAL\Model;
4
5
use BenTools\SimpleDBAL\Contract\AdapterInterface;
6
use BenTools\SimpleDBAL\Contract\CredentialsInterface;
7
use BenTools\SimpleDBAL\Model\Adapter\Mysqli\MysqliAdapter;
8
use BenTools\SimpleDBAL\Model\Adapter\PDO\PDOAdapter;
9
10
class SimpleDBAL
11
{
12
13
    const PDO    = 'pdo';
14
    const MYSQLI = 'mysqli';
15
16
    /**
17
     * @param CredentialsInterface $credentials
18
     * @param string $adapter
19
     * @return AdapterInterface
20
     */
21
    public static function factory(CredentialsInterface $credentials, string $adapter = self::PDO, array $options = null): AdapterInterface
22
    {
23
        switch ($adapter) {
24
            case self::PDO:
25
                return PDOAdapter::factory($credentials, $options);
26
27
            case self::MYSQLI:
28
                return MysqliAdapter::factory($credentials, $options);
29
30
            default:
31
                throw new \InvalidArgumentException("Invalid adapter.");
32
        }
33
    }
34
}
35