Completed
Push — master ( 5e6003...ff6361 )
by Matthew
03:07
created

AlertEndpointController   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 61
Duplicated Lines 32.79 %

Coupling/Cohesion

Components 1
Dependencies 3
Metric Value
dl 20
loc 61
wmc 5
lcom 1
cbo 3
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 1
A getSingle() 10 10 2
A getActives() 10 10 2

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 Ps2alerts\Api\Controller\Endpoint\Alerts;
4
5
use League\Fractal\Manager;
6
use Ps2alerts\Api\Controller\Endpoint\AbstractEndpointController;
7
use Ps2alerts\Api\Contract\ConfigAwareInterface;
8
use Ps2alerts\Api\Contract\ConfigAwareTrait;
9
use Ps2alerts\Api\Repository\AlertRepository;
10
use Ps2alerts\Api\Transformer\AlertTotalTransformer;
11
use Ps2alerts\Api\Transformer\AlertTransformer;
12
use Symfony\Component\HttpFoundation\Request;
13
use Symfony\Component\HttpFoundation\Response;
14
15
class AlertEndpointController extends AbstractEndpointController implements
16
    ConfigAwareInterface
17
{
18
    use ConfigAwareTrait;
19
20
    /**
21
     * Construct
22
     *
23
     * @param Ps2alerts\Api\Repository\AlertRepository   $repository
24
     * @param Ps2alerts\Api\Transformer\AlertTransformer $transformer
25
     * @param League\Fractal\Manager                     $fractal
26
     */
27
    public function __construct(
28
        AlertRepository  $repository,
29
        AlertTransformer $transformer,
30
        Manager          $fractal
31
    ) {
32
        $this->repository  = $repository;
33
        $this->transformer = $transformer;
34
        $this->fractal     = $fractal;
35
    }
36
37
    /**
38
     * Returns a single alert's information
39
     *
40
     * @param  Symfony\Component\HttpFoundation\Request  $request
41
     * @param  Symfony\Component\HttpFoundation\Response $response
42
     * @param  array                                     $args
43
     *
44
     * @return \League\Fractal\TransformerAbstract
45
     */
46 View Code Duplication
    public function getSingle(Request $request, Response $response, array $args)
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...
47
    {
48
        $alert = $this->repository->readSingleById($args['id']);
49
50
        if (empty($alert)) {
51
            return $this->errorEmpty($response);
52
        }
53
54
        return $this->respond('item', $alert, $this->transformer, $request, $response);
55
    }
56
57
    /**
58
     * Returns all currently running alerts
59
     *
60
     * @param  Symfony\Component\HttpFoundation\Request  $request
61
     * @param  Symfony\Component\HttpFoundation\Response $response
62
     *
63
     * @return \League\Fractal\TransformerAbstract
64
     */
65 View Code Duplication
    public function getActives(Request $request, Response $response)
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...
66
    {
67
        $actives = $this->repository->readAllByFields(['InProgress' => 1]);
68
69
        if (empty($actives)) {
70
            return $this->errorEmpty($response);
71
        }
72
73
        return $this->respond('collection', $actives, $this->transformer, $request, $response);
74
    }
75
}
76