Completed
Push — master ( 605918...00f053 )
by diego
02:53
created

TruncateTable   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 4
Bugs 1 Features 1
Metric Value
wmc 6
c 4
b 1
f 1
lcom 1
cbo 3
dl 0
loc 50
ccs 15
cts 15
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A enable() 0 4 1
A execute() 0 14 4
1
<?php
2
/**
3
 * TruncateTable.php
4
 */
5
namespace HDNET\Importr\Feature;
6
7
use HDNET\Importr\Processor\Configuration;
8
use HDNET\Importr\Service\DatabaseService;
9
use HDNET\Importr\Service\ManagerInterface;
10
11
/**
12
 * Class TruncateTable
13
 */
14
class TruncateTable extends AbstractFeature
15
{
16
    /**
17
     * @var DatabaseService
18
     */
19
    protected $databaseService;
20
21
    /**
22
     * TruncateTable constructor.
23
     * @param DatabaseService $databaseService
24
     */
25 3
    public function __construct(DatabaseService $databaseService)
26
    {
27 3
        $this->databaseService = $databaseService;
28 3
    }
29
30
    /**
31
     * @return void
32
     */
33 1
    public static function enable()
34
    {
35 1
        parent::enable('preParseConfiguration', Configuration::class);
36 1
    }
37
38
    /**
39
     * To truncate a table from the importr you
40
     * have to use the "truncate: " configuration.
41
     * If you pass a string, then the string is
42
     * interpreted as a table name. If you pass
43
     * an array, every element is used as a table
44
     * name.
45
     *
46
     * @param ManagerInterface $manager
47
     * @param array $configuration
48
     */
49 2
    public function execute(ManagerInterface $manager, array $configuration)
0 ignored issues
show
Unused Code introduced by
The parameter $manager is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
50
    {
51 2
        if (isset($configuration['truncate'])) {
52 2
            if (is_array($configuration['truncate'])) {
53 1
                foreach ($configuration['truncate'] as $table) {
54 1
                    $this->databaseService->getDatabaseConnection()
55 1
                        ->exec_TRUNCATEquery($table);
56
                }
57
            } else {
58 1
                $this->databaseService->getDatabaseConnection()
59 1
                    ->exec_TRUNCATEquery($configuration['truncate']);
60
            }
61
        }
62 2
    }
63
}
64