Completed
Push — staging ( 9fc02d...5845eb )
by Matthew
02:48
created

AlertEndpointController::getActives()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 10
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 10
loc 10
rs 9.4285
cc 2
eloc 5
nc 2
nop 2
1
<?php
2
3
namespace Ps2alerts\Api\Controller\Endpoint;
4
5
use League\Fractal\Manager;
6
use Ps2alerts\Api\Controller\Endpoint\AbstractEndpointController;
7
use Ps2alerts\Api\Repository\AlertRepository;
8
use Ps2alerts\Api\Transformer\AlertTransformer;
9
use Symfony\Component\HttpFoundation\Request;
10
use Symfony\Component\HttpFoundation\Response;
11
12
class AlertEndpointController extends AbstractEndpointController
13
{
14
    /**
15
     * Construct
16
     *
17
     * @param Ps2alerts\Api\Repository\AlertRepository   $repository
18
     * @param Ps2alerts\Api\Transformer\AlertTransformer $transformer
19
     * @param League\Fractal\Manager                     $fractal
20
     */
21
    public function __construct(
22
        AlertRepository  $repository,
23
        AlertTransformer $transformer,
24
        Manager          $fractal
25
    ) {
26
        $this->repository  = $repository;
27
        $this->transformer = $transformer;
28
        $this->fractal     = $fractal;
0 ignored issues
show
Documentation Bug introduced by
It seems like $fractal of type object<League\Fractal\Manager> is incompatible with the declared type object<League\Fractal> of property $fractal.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
29
    }
30
31
    /**
32
     * Returns a single alert's information
33
     *
34
     * @see AbstractEndpointController::respondWithItem
35
     *
36
     * @param  Symfony\Component\HttpFoundation\Request  $request
37
     * @param  Symfony\Component\HttpFoundation\Response $response
38
     * @param  array                                     $args
39
     *
40
     * @return array
41
     */
42 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...
43
    {
44
        $alert = $this->repository->readSingleById($args['id']);
45
46
        if (empty($alert)) {
47
            return $this->errorEmpty($response);
48
        }
49
50
        return $this->respond('item', $alert, $this->transformer, $request, $response);
51
    }
52
53 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...
54
    {
55
        $actives = $this->repository->readAllByField('InProgress', 1);
56
57
        if (empty($actives)) {
58
            return $this->errorEmpty($response);
59
        }
60
61
        return $this->respond('collection', $actives, $this->transformer, $request, $response);
62
    }
63
}
64