Code Duplication    Length = 17-18 lines in 2 locations

src/Promocodes.php 1 location

@@ 159-175 (lines=17) @@
156
        }
157
158
        try {
159
            if ($promocode = $this->check($code)) {
160
                if ($this->isSecondUsageAttempt($promocode)) {
161
                    throw new AlreadyUsedException;
162
                }
163
164
                $promocode->users()->attach(auth()->id(), [
165
                    'promocode_id' => $promocode->id,
166
                    'used_at' => Carbon::now(),
167
                ]);
168
169
                if(!is_null($promocode->amount_codes)){
170
                    $promocode->amount_codes -= 1;
171
                    $promocode->save();
172
                }
173
174
                return $promocode->load('users');
175
            }
176
        } catch (InvalidPromocodeException $exception) {
177
            //
178
        }

src/Traits/Rewardable.php 1 location

@@ 36-53 (lines=18) @@
33
    public function applyCode($code, $callback = null)
34
    {
35
        try {
36
            if ($promocode = Promocodes::check($code)) {
37
                if ($promocode->users()->wherePivot('user_id', $this->id)->exists()) {
38
                    throw new AlreadyUsedException;
39
                }
40
41
                $promocode->users()->attach($this->id, [
42
                    'promocode_id' => $promocode->id,
43
                    'used_at' => Carbon::now(),
44
                ]);
45
46
                $promocode->load('users');
47
48
                if (is_callable($callback)) {
49
                    $callback($promocode);
50
                }
51
52
                return $promocode;
53
            }
54
        } catch (InvalidPromocodeException $exception) {
55
            //
56
        }