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

TableDumperFactory   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 14
dl 0
loc 37
ccs 12
cts 12
cp 1
rs 10
c 0
b 0
f 0
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A getDumper() 0 15 3
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