Code Duplication    Length = 38-42 lines in 3 locations

src/Library/Database/Query/MySqlBuilder.php 3 locations

@@ 23-63 (lines=41) @@
20
     * @param array $values
21
     * @return bool
22
     */
23
    public function replace(array $values)
24
    {
25
        if (empty($values)) {
26
            return true;
27
        }
28
29
        // Since every insert gets treated like a batch insert, we will make sure the
30
        // bindings are structured in a way that is convenient for building these
31
        // inserts statements by verifying the elements are actually an array.
32
        if (! is_array(reset($values))) {
33
            $values = [$values];
34
        } else { // Sort the keys in each row alphabetically for consistency
35
            foreach ($values as $key => $value) {
36
                ksort($value);
37
                $values[$key] = $value;
38
            }
39
        }
40
41
        // We'll treat every insert like a batch insert so we can easily insert each
42
        // of the records into the database consistently. This will make it much
43
        // easier on the grammars to just handle one type of record insertion.
44
        $bindings = [];
45
46
        foreach ($values as $record) {
47
            foreach ($record as $value) {
48
                $bindings[] = $value;
49
            }
50
        }
51
52
        $sql = $this->grammar->compileReplace($this, $values);
53
54
        // Once we have compiled the insert statement's SQL we can execute it on the
55
        // connection and return a result as a boolean success indicator as that
56
        // is the same type of result returned by the raw connection instance.
57
        $bindings = $this->cleanBindings($bindings);
58
59
        return $this->connection->insert($sql, $bindings);
60
    }
61
62
    /**
63
     * Insert a new record into the database, update on primary key conflict.
64
     *
65
     * @param array $values
66
     * @return bool
@@ 68-105 (lines=38) @@
65
     * @param array $values
66
     * @return bool
67
     */
68
    public function insertUpdate(array $values)
69
    {
70
        if (empty($values)) {
71
            return true;
72
        }
73
74
        // Since every insert gets treated like a batch insert, we will make sure the
75
        // bindings are structured in a way that is convenient for building these
76
        // inserts statements by verifying the elements are actually an array.
77
        if (! is_array(reset($values))) {
78
            $values = [$values];
79
        } else { // Sort the keys in each row alphabetically for consistency
80
            foreach ($values as $key => $value) {
81
                ksort($value);
82
                $values[$key] = $value;
83
            }
84
        }
85
86
        // We'll treat every insert like a batch insert so we can easily insert each
87
        // of the records into the database consistently. This will make it much
88
        // easier on the grammars to just handle one type of record insertion.
89
        $bindings = [];
90
91
        foreach ($values as $record) {
92
            foreach ($record as $value) {
93
                $bindings[] = $value;
94
            }
95
        }
96
97
        $sql = $this->grammar->compileInsertUpdate($this, $values);
98
99
        // Once we have compiled the insert statement's SQL we can execute it on the
100
        // connection and return a result as a boolean success indicator as that
101
        // is the same type of result returned by the raw connection instance.
102
        $bindings = $this->cleanBindings($bindings);
103
104
        return $this->connection->insert($sql, $bindings);
105
    }
106
107
    /**
108
     * Insert a new record into the database, discard on primary key conflict.
@@ 113-154 (lines=42) @@
110
     * @param array $values
111
     * @return bool
112
     */
113
    public function insertIgnore(array $values)
114
    {
115
        if (empty($values)) {
116
            return true;
117
        }
118
119
        // Since every insert gets treated like a batch insert, we will make sure the
120
        // bindings are structured in a way that is convenient for building these
121
        // inserts statements by verifying the elements are actually an array.
122
        if (! is_array(reset($values))) {
123
            $values = [$values];
124
        } else {
125
            foreach ($values as $key => $value) {
126
                ksort($value);
127
                $values[$key] = $value;
128
            }
129
        }
130
131
        // We'll treat every insert like a batch insert so we can easily insert each
132
        // of the records into the database consistently. This will make it much
133
        // easier on the grammars to just handle one type of record insertion.
134
        $bindings = [];
135
136
        foreach ($values as $record) {
137
            foreach ($record as $value) {
138
                $bindings[] = $value;
139
            }
140
        }
141
142
        $sql = $this->grammar->compileInsertIgnore($this, $values);
143
144
        // Once we have compiled the insert statement's SQL we can execute it on the
145
        // connection and return a result as a boolean success indicator as that
146
        // is the same type of result returned by the raw connection instance.
147
148
        $bindings = $this->cleanBindings($bindings);
149
150
        return $this->connection->insert($sql, $bindings);
151
    }
152
153
    /**
154
     * Add a "where in raw" clause for integer values to the query.
155
     *
156
     * @param  string  $column
157
     * @param  \Illuminate\Contracts\Support\Arrayable|array  $values