Passed
Push — master ( 16eb74...e2e5d8 )
by Emmanuel
02:58
created

MySQL   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
dl 0
loc 38
ccs 10
cts 10
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getDriverOptions() 0 4 1
A loadData() 0 16 2
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
/**
20
 * Various methods related to MySQL
21
 */
22
class MySQL extends AbstractDBHelper
23
{
24
    /**
25
     * Send options to be able to load dataset
26
     * @return array
27
     */
28 46
    public static function getDriverOptions(): array
29
    {
30
        return [
31 46
            \PDO::MYSQL_ATTR_LOCAL_INFILE => true
32
        ];
33
    }
34
35
36
    /**
37
     * Load Data from a CSV
38
     * @param  string  $table
39
     * @param  string  $filename
40
     * @param  array   $fields
41
     * @param  string  $mode  Not in used here
42
     * @return string
43
     */
44 7
    public function loadData(
45
        string $table,
46
        string $filename,
47
        array $fields,
48
        string $mode
49
    ): string {
50 7
        $sql ="LOAD DATA LOCAL INFILE '{$filename}'
51 7
     REPLACE INTO TABLE {$table}
52 7
     FIELDS TERMINATED BY '|' ENCLOSED BY '\"' LINES TERMINATED BY '" . PHP_EOL . "'
53 7
     (`" . implode("`, `", $fields) . "`)";
54
        // Run the query if asked
55 7
        if ($this->pretend === false) {
56 6
            $this->conn->query($sql);
57
        }
58
59 6
        return $sql;
60
    }
61
}
62