Completed
Push — master ( 45aada...26ef87 )
by Matthew
02:32
created

EndpointBaseController::readSingle()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 0 Features 2
Metric Value
c 3
b 0
f 2
dl 0
loc 10
rs 9.4286
cc 2
eloc 5
nc 2
nop 2
1
<?php
2
3
namespace Ps2alerts\Api\Controller;
4
5
use Symfony\Component\HttpFoundation\Request;
6
use League\Route\Http\JsonResponse as Response;
7
use Ps2alerts\Api\QueryObjects\QueryObject;
8
9
abstract class EndpointBaseController
10
{
11
    protected $loader;
12
13
    /**
14
     * Returns a single entry
15
     *
16
     * @param  Symfony\Component\HttpFoundation\Request $request
17
     * @param  array   $args
18
     *
19
     * @return \League\Route\Http\JsonResponse
20
     */
21
    public function readSingle(Request $request, array $args)
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...
22
    {
23
        $return = $this->loader->readSingle($args['resultID']);
0 ignored issues
show
Bug introduced by
The method readSingle does only exist in Ps2alerts\Api\Loader\Met...Api\Loader\ResultLoader, but not in Ps2alerts\Api\Loader\Sta...tfitTotalsMetricsLoader.

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...
24
25
        if (empty($return)) {
26
            return new Response\NoContent();
27
        }
28
29
        return new Response\Ok($return);
30
    }
31
}
32