Completed
Push — master ( 015490...3fff3d )
by diego
06:23 queued 04:33
created

TruncateTable   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 2
dl 0
loc 48
ccs 0
cts 15
cp 0
rs 10
c 0
b 0
f 0

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
declare(strict_types=1);
4
/**
5
 * TruncateTable.php
6
 */
7
namespace HDNET\Importr\Feature;
8
9
use HDNET\Importr\Processor\Configuration;
10
use HDNET\Importr\Service\DatabaseService;
11
12
/**
13
 * Class TruncateTable
14
 */
15
class TruncateTable
16
{
17
    /**
18
     * @var DatabaseService
19
     */
20
    protected $databaseService;
21
22
    /**
23
     * TruncateTable constructor.
24
     *
25
     * @param DatabaseService $databaseService
26
     */
27
    public function __construct(DatabaseService $databaseService)
28
    {
29
        $this->databaseService = $databaseService;
30
    }
31
32
    public static function enable()
33
    {
34
        FeatureRegistry::enable('preParseConfiguration', Configuration::class);
35
    }
36
37
    /**
38
     * To truncate a table from the importr you
39
     * have to use the "truncate: " configuration.
40
     * If you pass a string, then the string is
41
     * interpreted as a table name. If you pass
42
     * an array, every element is used as a table
43
     * name.
44
     *
45
     * @param Configuration $processor
46
     * @param array         $configuration
47
     */
48
    public function execute(Configuration $processor, array $configuration)
0 ignored issues
show
Unused Code introduced by
The parameter $processor 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...
49
    {
50
        if (isset($configuration['truncate'])) {
51
            if (\is_array($configuration['truncate'])) {
52
                foreach ($configuration['truncate'] as $table) {
53
                    $this->databaseService->getDatabaseConnection()
54
                        ->exec_TRUNCATEquery($table);
55
                }
56
            } else {
57
                $this->databaseService->getDatabaseConnection()
58
                    ->exec_TRUNCATEquery($configuration['truncate']);
59
            }
60
        }
61
    }
62
}
63