Passed
Push — master ( e18e45...a1f222 )
by Emmanuel
03:09
created

AbstractDBHelper   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 76
Duplicated Lines 0 %

Test Coverage

Coverage 83.33%

Importance

Changes 0
Metric Value
wmc 5
eloc 13
dl 0
loc 76
ccs 10
cts 12
cp 0.8333
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A getEnclosureForCSV() 0 3 1
A getDriverOptions() 0 3 1
A setPretend() 0 5 1
A registerCustomTypes() 0 2 1
1
<?php
2
/**
3
 * neuralyzer : Data Anonymization Library and CLI Tool
4
 *
5
 * PHP Version 7.1
6
 *
7
 * @author Emmanuel Dyan
8
 * @copyright 2018 Emmanuel Dyan
9
 *
10
 * @package edyan/neuralyzer
11
 *
12
 * @license GNU General Public License v2.0
13
 *
14
 * @link https://github.com/edyan/neuralyzer
15
 */
16
17
namespace Edyan\Neuralyzer\Helper\DB;
18
19
use Doctrine\DBAL\Connection;
20
21
/**
22
 * Various methods to help interacting with DB servers
23
 */
24
abstract class AbstractDBHelper
25
{
26
    /**
27
     * Execute (or not) queries
28
     * @var bool
29
     */
30
    public $pretend = false;
31
32
    /**
33
     * DBAL connection
34
     * @var Connection
35
     */
36
    public $conn = null;
37
38
39
    /**
40
     * Requires a connection to work
41
     * @param Connection $conn
42
     */
43 53
    public function __construct(Connection $conn)
44
    {
45 53
        $this->conn = $conn;
46 53
    }
47
48
    /**
49
     * Set Pretend to true to simulate queries, false to execute interface
50
     * @param bool $pretend
51
     */
52 10
    public function setPretend(bool $pretend)
53
    {
54 10
        $this->pretend = $pretend;
55
56 10
        return $this;
57
    }
58
59
    /**
60
     * Get, for a driver options for connection (PDO)
61
     * @return array
62
     */
63 2
    public static function getDriverOptions(): array
64
    {
65 2
        return [];
66
    }
67
68
    /**
69
     * Set the right enclosure
70
     * @return string
71
     */
72 10
    public function getEnclosureForCSV(): string
73
    {
74 10
        return '"';
75
    }
76
77
    /**
78
     * Register doctrine custom types for driver
79
     *
80
     * @return void
81
     */
82
    public function registerCustomTypes(): void
83
    {
84
    }
85
86
    /**
87
     * Load Data from a CSV
88
     * @param  string  $table
89
     * @param  string  $filename
90
     * @param  array   $fields
91
     * @param  string  $mode  Not in used here
92
     * @return string
93
     */
94
    abstract public function loadData(
95
        string $table,
96
        string $filename,
97
        array $fields,
98
        string $mode
99
    ): string;
100
}
101