TableDumperFactory   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A getDumper() 0 15 3
1
<?php
2
/**
3
 * This file is part of graze/sprout.
4
 *
5
 * Copyright © 2018 Nature Delivered Ltd. <https://www.graze.com>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 *
10
 * @license https://github.com/graze/sprout/blob/master/LICENSE.md
11
 * @link    https://github.com/graze/sprout
12
 */
13
14
namespace Graze\Sprout\Dump;
15
16
use Graze\ParallelProcess\Pool;
17
use Graze\Sprout\Config\ConnectionConfigInterface;
18
use Graze\Sprout\Db\Mysql\MysqlTableDumper;
19
use InvalidArgumentException;
20
use Psr\Log\LoggerAwareInterface;
21
use Psr\Log\LoggerAwareTrait;
22
23
class TableDumperFactory implements LoggerAwareInterface
24
{
25
    use LoggerAwareTrait;
26
27
    /** @var Pool */
28
    private $processPool;
29
30
    /**
31
     * TableDumperFactory constructor.
32
     *
33
     * @param Pool $processPool
34
     */
35 3
    public function __construct(Pool $processPool)
36
    {
37 3
        $this->processPool = $processPool;
38 3
    }
39
40
    /**
41
     * @param ConnectionConfigInterface $connection
42
     *
43
     * @return TableDumperInterface
44
     */
45 3
    public function getDumper(ConnectionConfigInterface $connection): TableDumperInterface
46
    {
47 3
        $driver = $connection->getDriver();
48
49
        switch ($driver) {
50 3
            case 'mysql':
51 2
                if ($this->logger) {
52 1
                    $this->logger->debug(
53 1
                        "getDumper: using mysql dumper for driver: {$driver}",
54 1
                        ['driver' => $driver]
55
                    );
56
                }
57 2
                return new MysqlTableDumper($this->processPool, $connection);
58
            default:
59 1
                throw new InvalidArgumentException("getDumper: no dumper found for driver: `{$driver}`");
60
        }
61
    }
62
}
63