BetfairParamObject   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 1
dl 0
loc 22
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getResults() 0 6 1
A withParam() 0 5 1
A restoreDefaults() 0 4 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