Passed
Push — master ( 8fc551...e19a0d )
by Harry
02:28
created

TableSeederFactory::getSeeder()   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
 * 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\Seed;
15
16
use Graze\ParallelProcess\Pool;
17
use Graze\Sprout\Config\ConnectionConfigInterface;
18
use Graze\Sprout\Db\Mysql\MysqlTableSeeder;
19
use InvalidArgumentException;
20
use League\Flysystem\AdapterInterface;
21
use Psr\Log\LoggerAwareInterface;
22
use Psr\Log\LoggerAwareTrait;
23
24
class TableSeederFactory implements LoggerAwareInterface
25
{
26
    use LoggerAwareTrait;
27
28
    /** @var Pool */
29
    private $processPool;
30
    /** @var AdapterInterface */
31
    private $filesystem;
32
33
    /**
34
     * TableDumperFactory constructor.
35
     *
36
     * @param Pool             $processPool
37
     * @param AdapterInterface $filesystem
38
     */
39 3
    public function __construct(Pool $processPool, AdapterInterface $filesystem)
40
    {
41 3
        $this->processPool = $processPool;
42 3
        $this->filesystem = $filesystem;
43 3
    }
44
45
    /**
46
     * @param ConnectionConfigInterface $connection
47
     *
48
     * @return TableSeederInterface
49
     */
50 3
    public function getSeeder(ConnectionConfigInterface $connection): TableSeederInterface
51
    {
52 3
        $driver = $connection->getDriver();
53
54
        switch ($driver) {
55 3
            case 'mysql':
56 2
                if ($this->logger) {
57 1
                    $this->logger->debug(
58 1
                        "getSeeder: using mysql seeder for driver: {$driver}",
59 1
                        ['driver' => $driver]
60
                    );
61
                }
62 2
                return new MysqlTableSeeder($this->processPool, $connection, $this->filesystem);
63
            default:
64 1
                throw new InvalidArgumentException("getSeeder: no seeder found for driver: `{$driver}`");
65
        }
66
    }
67
}
68