Completed
Push — staging ( 83f973...0db769 )
by Matthew
02:32
created

AlertEndpointController::getVictories()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 16
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
c 2
b 0
f 1
dl 0
loc 16
rs 9.4285
cc 2
eloc 10
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\AlertTotalTransformer;
9
use Ps2alerts\Api\Transformer\AlertTransformer;
10
use Symfony\Component\HttpFoundation\Request;
11
use Symfony\Component\HttpFoundation\Response;
12
13
class AlertEndpointController extends AbstractEndpointController
14
{
15
    /**
16
     * Construct
17
     *
18
     * @param Ps2alerts\Api\Repository\AlertRepository   $repository
19
     * @param Ps2alerts\Api\Transformer\AlertTransformer $transformer
20
     * @param League\Fractal\Manager                     $fractal
21
     */
22
    public function __construct(
23
        AlertRepository  $repository,
24
        AlertTransformer $transformer,
25
        Manager          $fractal
26
    ) {
27
        $this->repository  = $repository;
28
        $this->transformer = $transformer;
29
        $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...
30
    }
31
32
    /**
33
     * Returns a single alert's information
34
     *
35
     * @see AbstractEndpointController::respondWithItem
36
     *
37
     * @param  Symfony\Component\HttpFoundation\Request  $request
38
     * @param  Symfony\Component\HttpFoundation\Response $response
39
     * @param  array                                     $args
40
     *
41
     * @return array
42
     */
43
    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...
44
    {
45
        $alert = $this->repository->readSingleById($args['id']);
46
47
        if (empty($alert)) {
48
            return $this->errorEmpty($response);
49
        }
50
51
        return $this->respond('item', $alert, $this->transformer, $request, $response);
52
    }
53
54
    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...
55
    {
56
        $actives = $this->repository->readAllByFields(['InProgress', 1]);
57
58
        if (empty($actives)) {
59
            return $this->errorEmpty($response);
60
        }
61
62
        return $this->respond('collection', $actives, $this->transformer, $request, $response);
63
    }
64
65
    /**
66
     * Returns the victories of each faction and the totals
67
     *
68
     * @param  Symfony\Component\HttpFoundation\Request  $request
69
     * @param  Symfony\Component\HttpFoundation\Response $response
70
     * @param  array                                     $args
0 ignored issues
show
Bug introduced by
There is no parameter named $args. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
71
     *
72
     * @return array
73
     */
74
    public function getVictories(Request $request, Response $response)
75
    {
76
        $counts = [
77
            'vs'          => $this->repository->readCountByFields(['ResultWinner' => 'VS', 'Valid' => 1]),
78
            'nc'          => $this->repository->readCountByFields(['ResultWinner' => 'NC', 'Valid' => 1]),
79
            'tr'          => $this->repository->readCountByFields(['ResultWinner' => 'TR', 'Valid' => 1]),
80
            'draw'        => $this->repository->readCountByFields(['ResultDraw' => 1, 'Valid' => 1]),
81
            'total'       => $this->repository->readCountByFields(['Valid' => 1])
82
        ];
83
84
        if (empty($counts['total'])) {
85
            return $this->errorEmpty($response);
86
        }
87
88
        return $this->respond('item', $counts, new AlertTotalTransformer, $request, $response);
89
    }
90
91
    /**
92
     * Returns the dominations of each faction and the totals
93
     *
94
     * @param  Symfony\Component\HttpFoundation\Request  $request
95
     * @param  Symfony\Component\HttpFoundation\Response $response
96
     *
97
     * @return array
98
     */
99
    public function getDominations(Request $request, Response $response)
100
    {
101
        $counts = [
102
            'vs'          => $this->repository->readCountByFields(['ResultWinner' => 'VS', 'Valid' => 1, 'ResultDomination' => 1]),
103
            'nc'          => $this->repository->readCountByFields(['ResultWinner' => 'NC', 'Valid' => 1, 'ResultDomination' => 1]),
104
            'tr'          => $this->repository->readCountByFields(['ResultWinner' => 'TR', 'Valid' => 1, 'ResultDomination' => 1]),
105
            'total'       => $this->repository->readCountByFields(['Valid' => 1, 'ResultDomination' => 1])
106
        ];
107
108
        if (empty($counts['total'])) {
109
            return $this->errorEmpty($response);
110
        }
111
112
        return $this->respond('item', $counts, new AlertTotalTransformer, $request, $response);
113
    }
114
}
115