Completed
Push — master ( 4c78b7...7d76a2 )
by diego
04:44
created

TruncateTable::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
namespace HDNET\Importr\Feature;
3
4
use HDNET\Importr\Domain\Model\Import;
5
use HDNET\Importr\Service\DatabaseService;
6
use HDNET\Importr\Service\ManagerInterface;
7
8
class TruncateTable extends AbstractFeature
9
{
10
    /**
11
     * @var DatabaseService
12
     */
13
    protected $databaseService;
14
15
    /**
16
     * TruncateTable constructor.
17
     * @param DatabaseService $databaseService
18
     */
19 3
    public function __construct(DatabaseService $databaseService)
20
    {
21 3
        $this->databaseService = $databaseService;
22 3
    }
23
24
    /**
25
     * To truncate a table from the importr you
26
     * have to use the "truncate: " configuration.
27
     * If you pass a string, then the string is
28
     * interpreted as a table name. If you pass
29
     * an array, every element is used as a table
30
     * name.
31
     *
32
     * @param ManagerInterface $manager
33
     * @param Import $import
34
     */
35 3
    public function execute(ManagerInterface $manager, Import $import)
36
    {
37 3
        $configuration = $import->getStrategy()
38 3
            ->getConfiguration();
39 3
        if (isset($configuration['truncate'])) {
40 2
            if (is_array($configuration['truncate'])) {
41 1
                foreach ($configuration['truncate'] as $table) {
42 1
                    $this->databaseService->getDatabaseConnection()
43 1
                        ->exec_TRUNCATEquery($table);
44
                }
45
            } else {
46 1
                $this->databaseService->getDatabaseConnection()
47 1
                    ->exec_TRUNCATEquery($configuration['truncate']);
48
            }
49
        }
50 3
    }
51
}
52