Code Duplication    Length = 20-20 lines in 2 locations

src/Promocodes.php 1 location

@@ 140-159 (lines=20) @@
137
     *
138
     * @return static
139
     */
140
    public function create($amount = 1, $reward = null, array $data = [])
141
    {
142
        $records = [];
143
144
        // loop though each promocodes required
145
        foreach ($this->output($amount) as $code) {
146
            $records[] = [
147
                'code' => $code,
148
                'reward' => $reward,
149
                'data' => json_encode($data),
150
            ];
151
        }
152
153
        // check for insertion of record
154
        if (Promocode::insert($records)) {
155
            return collect($records);
156
        }
157
158
        return collect([]);
159
    }
160
161
    /**
162
     * Check promocode in database if it is valid.

src/Traits/Rewardable.php 1 location

@@ 19-38 (lines=20) @@
16
     *
17
     * @return mixed
18
     */
19
    public function createCode($amount = 1, $reward = null, array $data = [])
20
    {
21
        $records = [];
22
23
        // loop though each promocodes required
24
        foreach (Promocodes::output($amount) as $code) {
25
            $records[] = new Promocode([
26
                'code'   => $code,
27
                'reward' => $reward,
28
                'data'   => json_encode($data),
29
            ]);
30
        }
31
32
        // check for insertion of record
33
        if ($this->promocodes()->saveMany($records)) {
34
            return collect($records);
35
        }
36
37
        return collect([]);
38
    }
39
40
    /**
41
     * Apply promocode for user and get callback.