Passed
Pull Request — master (#3)
by Harry
02:24
created

TableDumperFactory::getDumper()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 15
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 3

Importance

Changes 0
Metric Value
cc 3
eloc 10
nc 3
nop 1
dl 0
loc 15
ccs 9
cts 9
cp 1
crap 3
rs 9.9332
c 0
b 0
f 0
1
<?php
2
3
namespace Graze\Sprout\Dump;
4
5
use Graze\ParallelProcess\Pool;
6
use Graze\ParallelProcess\Table;
7
use Graze\Sprout\Config\ConnectionConfigInterface;
8
use Graze\Sprout\Dump\Mysql\MysqlTableDumper;
9
use InvalidArgumentException;
10
use Psr\Log\LoggerAwareInterface;
11
use Psr\Log\LoggerAwareTrait;
12
13
class TableDumperFactory implements LoggerAwareInterface
14
{
15
    use LoggerAwareTrait;
16
17
    /** @var Pool */
18
    private $processPool;
19
20
    /**
21
     * TableDumperFactory constructor.
22
     *
23
     * @param Pool $processPool
24
     */
25 3
    public function __construct(Pool $processPool)
26
    {
27 3
        $this->processPool = $processPool;
28 3
    }
29
30
    /**
31
     * @param ConnectionConfigInterface $connection
32
     *
33
     * @return TableDumperInterface
34
     */
35 3
    public function getDumper(ConnectionConfigInterface $connection): TableDumperInterface
36
    {
37 3
        $driver = $connection->getDriver();
38
39
        switch ($driver) {
40 3
            case 'mysql':
41 2
                if ($this->logger) {
42 1
                    $this->logger->debug(
43 1
                        "getDumper: using mysql dumper for driver: {$driver}",
44 1
                        ['driver' => $driver]
45
                    );
46
                }
47 2
                return new MysqlTableDumper($this->processPool, $connection);
48
            default:
49 1
                throw new InvalidArgumentException("getDumper: no dumper found for driver: `{$driver}`");
50
        }
51
    }
52
}
53