Passed
Pull Request — master (#3)
by Harry
03:37 queued 01:14
created

TableChopperFactory::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
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 3
    public function __construct(Pool $processPool)
38
    {
39 3
        $this->processPool = $processPool;
40 3
    }
41
42
    /**
43
     * @param ConnectionConfigInterface $connection
44
     *
45
     * @return TableChopperInterface
46
     */
47 3
    public function getChopper(ConnectionConfigInterface $connection): TableChopperInterface
48
    {
49 3
        $driver = $connection->getDriver();
50
51
        switch ($driver) {
52 3
            case 'mysql':
53 2
                if ($this->logger) {
54 1
                    $this->logger->debug(
55 1
                        "getChopper: using mysql chopper for driver: {$driver}",
56 1
                        ['driver' => $driver]
57
                    );
58
                }
59 2
                return new MysqlTableChopper($this->processPool, $connection);
60
            default:
61 1
                throw new InvalidArgumentException("getChopper: no chopper found for driver: `{$driver}`");
62
        }
63
    }
64
}
65