Passed
Pull Request — master (#2)
by Harry
05:16 queued 02:33
created

TableChopperFactory::getChopper()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 15
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 3.243

Importance

Changes 0
Metric Value
cc 3
eloc 10
nc 3
nop 1
dl 0
loc 15
ccs 7
cts 10
cp 0.7
crap 3.243
rs 9.9332
c 0
b 0
f 0
1
<?php
2
/**
3
 * This file is part of graze/sprout.
4
 *
5
 * Copyright (c) 2017 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\Chop;
15
16
use Graze\ParallelProcess\Pool;
17
use Graze\Sprout\Chop\Mysql\MysqlTableChopper;
18
use Graze\Sprout\Config\ConnectionConfigInterface;
19
use InvalidArgumentException;
20
use Psr\Log\LoggerAwareInterface;
21
use Psr\Log\LoggerAwareTrait;
22
23
class TableChopperFactory 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
     * @internal param OutputInterface $output
36
     */
37 2
    public function __construct(Pool $processPool)
38
    {
39 2
        $this->processPool = $processPool;
40 2
    }
41
42
    /**
43
     * @param ConnectionConfigInterface $connection
44
     *
45
     * @return TableChopperInterface
46
     */
47 2
    public function getChopper(ConnectionConfigInterface $connection): TableChopperInterface
48
    {
49 2
        $driver = $connection->getDriver();
50
51 2
        switch ($driver) {
52 2
            case 'mysql':
53 1
                if ($this->logger) {
54
                    $this->logger->debug(
55
                        "getChopper: using mysql chopper for driver: {$driver}",
56
                        ['driver' => $driver]
57
                    );
58
                }
59 1
                return new MysqlTableChopper($this->processPool, $connection);
60
            default:
61 1
                throw new InvalidArgumentException("getChopper: no chopper found for driver: `{$driver}`");
62
        }
63
    }
64
}
65