Chopper   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 44
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 44
ccs 13
cts 13
cp 1
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 1
A chop() 0 13 2
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\Chop;
15
16
use Graze\Sprout\Config\SchemaConfigInterface;
17
use Symfony\Component\Console\Output\OutputInterface;
18
19
class Chopper
20
{
21
    /** @var SchemaConfigInterface */
22
    private $schemaConfig;
23
    /** @var OutputInterface */
24
    private $output;
25
    /** @var TableChopperFactory */
26
    private $factory;
27
28
    /**
29
     * Chopper constructor.
30
     *
31
     * @param SchemaConfigInterface $schemaConfig
32
     * @param OutputInterface       $output
33
     * @param TableChopperFactory   $factory
34
     */
35 4
    public function __construct(
36
        SchemaConfigInterface $schemaConfig,
37
        OutputInterface $output,
38
        TableChopperFactory $factory
39
    ) {
40 4
        $this->schemaConfig = $schemaConfig;
41 4
        $this->output = $output;
42 4
        $this->factory = $factory;
43 4
    }
44
45
    /**
46
     * Chop a collection of files to tables
47
     *
48
     * @param string[] $tables
49
     */
50 4
    public function chop(array $tables = [])
51
    {
52 4
        $tables = array_unique($tables);
53
54 4
        if (count($tables) === 0) {
55 1
            $this->output->writeln('<warning>No tables specified, nothing to do</warning>');
56 1
            return;
57
        }
58
59 3
        $tableChopper = $this->factory->getChopper($this->schemaConfig->getConnection());
60 3
        $schema = $this->schemaConfig->getSchema();
61
62 3
        $tableChopper->chop($schema, ...$tables);
63 3
    }
64
}
65