BetfairParamObject::withParam()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
namespace Betfair\BettingApi;
4
5
use Betfair\AbstractBetfair;
6
use Betfair\Model\ParamInterface;
7
8
class BetfairParamObject extends AbstractBetfair
9
{
10
    protected $param;
11
12
    public function getResults()
13
    {
14
        $response = $this->executeCustomQuery($this->param);
0 ignored issues
show
Bug introduced by
It seems like $this->param can be null; however, executeCustomQuery() does not accept null, maybe add an additional type check?

Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code:

/** @return stdClass|null */
function mayReturnNull() { }

function doesNotAcceptNull(stdClass $x) { }

// With potential error.
function withoutCheck() {
    $x = mayReturnNull();
    doesNotAcceptNull($x); // Potential error here.
}

// Safe - Alternative 1
function withCheck1() {
    $x = mayReturnNull();
    if ( ! $x instanceof stdClass) {
        throw new \LogicException('$x must be defined.');
    }
    doesNotAcceptNull($x);
}

// Safe - Alternative 2
function withCheck2() {
    $x = mayReturnNull();
    if ($x instanceof stdClass) {
        doesNotAcceptNull($x);
    }
}
Loading history...
15
        $this->restoreDefaults();
16
        return $response;
17
    }
18
19
    public function withParam(ParamInterface $param)
20
    {
21
        $this->param = $param;
22
        return $this;
23
    }
24
25
    private function restoreDefaults()
26
    {
27
        $this->param = null;
28
    }
29
}
30