SubscriberController::getSubscribers()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 6
rs 9.4286
cc 1
eloc 3
nc 1
nop 1
1
<?php
2
3
/*
4
 * This file is part of Gitamin.
5
 *
6
 * Copyright (C) 2015-2016 The Gitamin Team
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Gitamin\Http\Controllers\Api;
13
14
use Gitamin\Commands\Subscriber\SubscribeSubscriberCommand;
15
use Gitamin\Commands\Subscriber\UnsubscribeSubscriberCommand;
16
use Gitamin\Models\Subscriber;
17
use Illuminate\Database\QueryException;
18
use Illuminate\Foundation\Bus\DispatchesJobs;
19
use Illuminate\Http\Request;
20
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
21
22
class SubscriberController extends AbstractApiController
23
{
24
    use DispatchesJobs;
25
26
    /**
27
     * Get all subscribers.
28
     *
29
     * @param \Symfony\Component\HttpFoundation\Request $request
30
     *
31
     * @return \Illuminate\Http\JsonResponse
32
     */
33
    public function getSubscribers(Request $request)
34
    {
35
        $subscribers = Subscriber::paginate($request->get('per_page', 20));
36
37
        return $this->paginator($subscribers, $request);
38
    }
39
40
    /**
41
     * Create a new subscriber.
42
     *
43
     * @return \Illuminate\Http\JsonResponse
44
     */
45 View Code Duplication
    public function postSubscribers(Request $request)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
46
    {
47
        try {
48
            $subscriber = $this->dispatch(new SubscribeSubscriberCommand($request->get('email'), $request->get('verify', false)));
49
        } catch (QueryException $e) {
50
            throw new BadRequestHttpException();
51
        }
52
53
        return $this->item($subscriber);
54
    }
55
56
    /**
57
     * Delete a subscriber.
58
     *
59
     * @param \Gitamin\Models\Subscriber $subscriber
60
     *
61
     * @return \Illuminate\Http\JsonResponse
62
     */
63
    public function deleteSubscriber(Subscriber $subscriber)
64
    {
65
        $this->dispatch(new UnsubscribeSubscriberCommand($subscriber));
66
67
        return $this->noContent();
68
    }
69
}
70