Code Duplication    Length = 26-26 lines in 2 locations

src/Library/Database/Query/Grammars/MySqlGrammar.php 2 locations

@@ 19-44 (lines=26) @@
16
     * @param array $data
17
     * @return string
18
     */
19
    public function compileReplace(Builder $query, array $data)
20
    {
21
        // Essentially we will force every insert to be treated as a batch insert which
22
        // simply makes creating the SQL easier for us since we can utilize the same
23
        // basic routine regardless of an amount of records given to us to insert.
24
        $table = $this->wrapTable($query->from);
25
26
        if (! is_array(reset($data))) {
27
            $data = [$data];
28
        }
29
30
        $columns = $this->columnize(array_keys(reset($data)));
31
32
        // We need to build a list of parameter place-holders of values that are bound
33
        // to the query. Each insert should have the exact same amount of parameter
34
        // bindings so we will loop through the record and parameterize them all.
35
        $values = [];
36
37
        foreach ($data as $record) {
38
            $values[] = '('.$this->parameterize($record).')';
39
        }
40
41
        $values = implode(', ', $values);
42
43
        return "REPLACE INTO {$table} ({$columns}) VALUES {$values}";
44
    }
45
46
    /**
47
     * Compile an insert ignore statement into SQL.
@@ 55-80 (lines=26) @@
52
     * @param array $data
53
     * @return string
54
     */
55
    public function compileInsertIgnore(Builder $query, array $data)
56
    {
57
        // Essentially we will force every insert to be treated as a batch insert which
58
        // simply makes creating the SQL easier for us since we can utilize the same
59
        // basic routine regardless of an amount of records given to us to insert.
60
        $table = $this->wrapTable($query->from);
61
62
        if (! is_array(reset($data))) {
63
            $data = [$data];
64
        }
65
66
        $columns = $this->columnize(array_keys(reset($data)));
67
68
        // We need to build a list of parameter place-holders of values that are bound
69
        // to the query. Each insert should have the exact same amount of parameter
70
        // bindings so we will loop through the record and parameterize them all.
71
        $values = [];
72
73
        foreach ($data as $record) {
74
            $values[] = '('.$this->parameterize($record).')';
75
        }
76
77
        $values = implode(', ', $values);
78
79
        return "INSERT IGNORE INTO {$table} ({$columns}) VALUES {$values}";
80
    }
81
82
    /**
83
     * Compile an insert update statement into SQL.