SubscriptionPaginateAction   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 67
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
dl 67
loc 67
rs 10
c 0
b 0
f 0
wmc 2
lcom 0
cbo 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 5 5 1
A __invoke() 10 10 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace Finder\Http\Actions;
4
5
use Finder\Http\Requests\PaginatedRequest;
6
use Finder\Http\Resources\PaginatedResource;
7
use Finder\Http\Resources\SubscriptionPlainResource;
8
use Population\Manipule\Managers\SubscriptionManager;
9
use Illuminate\Contracts\Routing\ResponseFactory;
10
use Illuminate\Http\JsonResponse;
11
12
/**
13
 * Class SubscriptionPaginateAction.
14
 *
15
 * @package Finder\Http\Actions
16
 */
17 View Code Duplication
class SubscriptionPaginateAction
0 ignored issues
show
Duplication introduced by
This class 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...
18
{
19
    /**
20
     * @var ResponseFactory
21
     */
22
    private $responseFactory;
23
24
    /**
25
     * @var SubscriptionManager
26
     */
27
    private $subscriptionManager;
28
29
    /**
30
     * SubscriptionPaginateAction constructor.
31
     *
32
     * @param ResponseFactory     $responseFactory
33
     * @param SubscriptionManager $subscriptionManager
34
     */
35
    public function __construct(ResponseFactory $responseFactory, SubscriptionManager $subscriptionManager)
36
    {
37
        $this->responseFactory = $responseFactory;
38
        $this->subscriptionManager = $subscriptionManager;
39
    }
40
41
    /**
42
     * @apiVersion        1.0.0
43
     * @api               {get} /v1/subscriptions?page=:page&per_page=:per_page Paginate
44
     * @apiName           Paginate
45
     * @apiGroup          Subscriptions
46
     * @apiHeader         {String} Accept application/json
47
     * @apiParam          {Integer{1..N}} [page=1]
48
     * @apiParam          {Integer{1..100}} [per_page=20]
49
     * @apiSuccessExample {json} Success-Response:
50
     * HTTP/1.1 200 OK
51
     * {
52
     *     "total": 100,
53
     *     "per_page": 10,
54
     *     "current_page": 2,
55
     *     "last_page": 10,
56
     *     "next_page_url": "http://path/to/api/resource?page=3",
57
     *     "prev_page_url": "http://path/to/api/resource?page=1",
58
     *     "from": 10,
59
     *     "to": 20,
60
     *     "data": [
61
     *         {
62
     *             "email": "[email protected]",
63
     *             "token": "subscription_token_string"
64
     *         }
65
     *     ]
66
     * }
67
     */
68
69
    /**
70
     * @param  PaginatedRequest $request
71
     * @return JsonResponse
72
     */
73
    public function __invoke(PaginatedRequest $request): JsonResponse
74
    {
75
        $paginator = $this->subscriptionManager->paginate(
76
            $request->get('page', 1),
77
            $request->get('per_page', 20),
78
            $request->query()
79
        );
80
81
        return $this->responseFactory->json(new PaginatedResource($paginator, SubscriptionPlainResource::class), JsonResponse::HTTP_OK);
82
    }
83
}
84