ResourceResponder   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 16
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 2
dl 0
loc 16
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A success() 0 11 2
1
<?php
2
3
namespace Scheduler\Web\Radar\Responder;
4
5
class ResourceResponder extends ApiProblemResponder
6
{
7
    protected $resource;
8
9
    protected function success()
10
    {
11
        $this->response = $this->response->withStatus(200);
12
        $output = $this->payload->getOutput();
13
14
        if (is_array($output)) {
15
            $this->jsonBody($this->resource->collection($output));
0 ignored issues
show
Bug introduced by
The method collection does only exist in Scheduler\Web\Resource\ShiftResource, but not in Scheduler\Web\Resource\H...b\Resource\UserResource.

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...
16
        } else {
17
            $this->jsonBody($this->resource->item($output));
18
        }
19
    }
20
}
21