Completed
Push — master ( beb1f2...8ae23c )
by Matthew
06:13
created

AlertStatisticsEndpoint::readAlertHistory()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 12
rs 9.4286
cc 2
eloc 6
nc 2
nop 1
1
<?php
2
3
namespace Ps2alerts\Api\Controller\Statistics;
4
5
use League\Route\Http\JsonResponse as Response;
6
use Ps2alerts\Api\Controller\EndpointBaseController;
7
use Ps2alerts\Api\Loader\Statistics\AlertStatisticsLoader;
8
use Symfony\Component\HttpFoundation\Request;
9
10
class AlertStatisticsEndpoint extends EndpointBaseController
11
{
12
    /**
13
     * Construct
14
     *
15
     * @param \Ps2alerts\Api\Loader\Statistics\AlertStatisticsLoader $loader
16
     */
17
    public function __construct(AlertStatisticsLoader $loader)
18
    {
19
        $this->loader = $loader;
20
    }
21
22
    /**
23
     * Gets total alerts based on provided parameters
24
     *
25
     * @param  \Symfony\Component\HttpFoundation\Request $request
26
     *
27
     * @return \League\Route\Http\JsonResponse
28
     */
29
    public function readTotals(Request $request)
30
    {
31
        $post = $request->request->all();
32
33
        $return = $this->loader->readTotals($post);
0 ignored issues
show
Bug introduced by
The method readTotals does only exist in Ps2alerts\Api\Loader\Sta...s\AlertStatisticsLoader, but not in Ps2alerts\Api\Loader\Ale...\PlayerStatisticsLoader.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
34
35
        if (empty($return)) {
36
            return new Response\NoContent();
37
        }
38
39
        return new Response\Ok($return);
40
    }
41
42
    /**
43
     * Retrieves the zones totals
44
     *
45
     * @param  \Symfony\Component\HttpFoundation\Request $request
46
     *
47
     * @return \League\Route\Http\JsonResponse
48
     */
49
    public function readZoneTotals(Request $request)
0 ignored issues
show
Unused Code introduced by
The parameter $request is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
50
    {
51
        $return = $this->loader->readZoneTotals();
0 ignored issues
show
Bug introduced by
The method readZoneTotals does only exist in Ps2alerts\Api\Loader\Sta...s\AlertStatisticsLoader, but not in Ps2alerts\Api\Loader\Ale...\PlayerStatisticsLoader.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
52
53
        if (empty($return)) {
54
            return new Response\NoContent();
55
        }
56
57
        return new Response\Ok($return);
58
    }
59
60
    /**
61
     * Retrieves the victory summary (daily or monthly)
62
     *
63
     * @param  \Symfony\Component\HttpFoundation\Request $request
64
     *
65
     * @return \League\Route\Http\JsonResponse
66
     */
67
    public function readHistorySummary(Request $request)
68
    {
69
        $post = $request->request->all();
70
71
        $return = $this->loader->readHistorySummary($post);
0 ignored issues
show
Bug introduced by
The method readHistorySummary does only exist in Ps2alerts\Api\Loader\Sta...s\AlertStatisticsLoader, but not in Ps2alerts\Api\Loader\Ale...\PlayerStatisticsLoader.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
72
73
        if (empty($return)) {
74
            return new Response\NoContent();
75
        }
76
77
        return new Response\Ok($return);
78
    }
79
80
    /**
81
     * Retrives a list of alerts based off filters
82
     *
83
     * @param  \Symfony\Component\HttpFoundation\Request $request
84
     *
85
     * @return \League\Route\Http\JsonResponse
86
     */
87
    public function readAlertHistory(Request $request)
88
    {
89
        $post = $request->request->all();
90
91
        $return = $this->loader->readAlertHistory($post);
0 ignored issues
show
Bug introduced by
The method readAlertHistory does only exist in Ps2alerts\Api\Loader\Sta...s\AlertStatisticsLoader, but not in Ps2alerts\Api\Loader\Ale...\PlayerStatisticsLoader.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
92
93
        if (empty($return)) {
94
            return new Response\NoContent();
95
        }
96
97
        return new Response\Ok($return);
98
    }
99
}
100