Completed
Branch develop (3cde25)
by Adam
14:50
created

AbstractClient   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 4
c 2
b 0
f 0
lcom 0
cbo 3
dl 0
loc 36
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 4
1
<?php
2
3
namespace IBM\Watson\Common;
4
5
use Http\Client\HttpClient;
6
use Http\Discovery\HttpClientDiscovery;
7
use IBM\Watson\Common\Hydrator\HydratorInterface;
8
use IBM\Watson\Common\Hydrator\ModelHydrator;
9
10
abstract class AbstractClient
11
{
12
    /**
13
     * @var \IBM\Watson\Common\Hydrator\ModelHydrator
14
     */
15
    protected $hydrator;
16
17
    /**
18
     * @var \Http\Client\HttpClient
19
     */
20
    protected $httpClient;
21
22
    /**
23
     * @var \IBM\Watson\Common\RequestBuilder
24
     */
25
    protected $requestBuilder;
26
27
    /**
28
     * Client constructor.
29
     *
30
     * @param \Http\Client\HttpClient|null                       $httpClient
31
     * @param \IBM\Watson\Common\Hydrator\HydratorInterface|null $hydrator
32
     * @param \IBM\Watson\Common\RequestBuilder|null             $requestBuilder
33
     *
34
     * @throws \Http\Discovery\Exception\NotFoundException
35
     */
36
    public function __construct(
37
        HttpClient $httpClient = null,
38
        HydratorInterface $hydrator = null,
39
        RequestBuilder $requestBuilder = null
40
    ) {
41
        $this->httpClient = $httpClient ?: HttpClientDiscovery::find();
42
        $this->hydrator = $hydrator ?: new ModelHydrator;
0 ignored issues
show
Documentation Bug introduced by
$hydrator ?: new \IBM\Wa...ydrator\ModelHydrator() is of type object<IBM\Watson\Common...ator\HydratorInterface>, but the property $hydrator was declared to be of type object<IBM\Watson\Common\Hydrator\ModelHydrator>. Are you sure that you always receive this specific sub-class here, or does it make sense to add an instanceof check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a given class or a super-class is assigned to a property that is type hinted more strictly.

Either this assignment is in error or an instanceof check should be added for that assignment.

class Alien {}

class Dalek extends Alien {}

class Plot
{
    /** @var  Dalek */
    public $villain;
}

$alien = new Alien();
$plot = new Plot();
if ($alien instanceof Dalek) {
    $plot->villain = $alien;
}
Loading history...
43
        $this->requestBuilder = $requestBuilder ?: new RequestBuilder;
44
    }
45
}
46