AbstractDBHelper   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 71
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 13
c 2
b 0
f 0
dl 0
loc 71
ccs 12
cts 12
cp 1
rs 10
wmc 5

5 Methods

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