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

TruncateTable   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 100%

Importance

Changes 3
Bugs 0 Features 1
Metric Value
wmc 5
c 3
b 0
f 1
lcom 1
cbo 5
dl 0
loc 44
ccs 14
cts 14
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A execute() 0 16 4
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