These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | namespace IBM\Watson\VisualRecognition; |
||
4 | |||
5 | use Http\Client\HttpClient; |
||
6 | use Http\Discovery\HttpClientDiscovery; |
||
7 | use IBM\Watson\Common\HttpClient\Builder; |
||
8 | use IBM\Watson\Common\Hydrator\HydratorInterface; |
||
9 | use IBM\Watson\Common\Hydrator\ModelHydrator; |
||
10 | use IBM\Watson\Common\RequestBuilder; |
||
11 | |||
12 | final class Client |
||
13 | { |
||
14 | /** |
||
15 | * @var string |
||
16 | */ |
||
17 | const BASE_URI = 'https://gateway-a.watsonplatform.net/visual-recognition/api'; |
||
18 | |||
19 | /** |
||
20 | * @var \Http\Client\HttpClient |
||
21 | */ |
||
22 | private $httpClient; |
||
23 | |||
24 | /** |
||
25 | * @var \IBM\Watson\Common\Hydrator\ModelHydrator |
||
26 | */ |
||
27 | private $hydrator; |
||
28 | |||
29 | /** |
||
30 | * @var \IBM\Watson\Common\RequestBuilder |
||
31 | */ |
||
32 | private $requestBuilder; |
||
33 | |||
34 | /** |
||
35 | * Client constructor. |
||
36 | * |
||
37 | * @param $httpClient |
||
38 | * @param $hydrator |
||
39 | * @param $requestBuilder |
||
40 | * |
||
41 | * @throws \Http\Discovery\Exception\NotFoundException |
||
42 | */ |
||
43 | View Code Duplication | public function __construct( |
|
0 ignored issues
–
show
|
|||
44 | HttpClient $httpClient = null, |
||
45 | HydratorInterface $hydrator = null, |
||
46 | RequestBuilder $requestBuilder = null |
||
47 | ) { |
||
48 | $this->httpClient = $httpClient ?: HttpClientDiscovery::find(); |
||
49 | $this->hydrator = $hydrator ?: new ModelHydrator; |
||
0 ignored issues
–
show
$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...
|
|||
50 | $this->requestBuilder = $requestBuilder ?: new RequestBuilder; |
||
51 | } |
||
52 | |||
53 | /** |
||
54 | * Create VisualRecognition client |
||
55 | * |
||
56 | * @param string $apiKey |
||
57 | * |
||
58 | * @return \IBM\Watson\VisualRecognition\Client |
||
59 | * |
||
60 | * @throws \Http\Discovery\Exception\NotFoundException |
||
61 | */ |
||
62 | public static function create($apiKey) |
||
63 | { |
||
64 | $httpClient = (new Builder()) |
||
65 | ->withEndpoint(static::BASE_URI) |
||
66 | ->withApiKey($apiKey) |
||
67 | ->withVersion(\date('Y-m-d')) |
||
68 | ->createConfiguredClient(); |
||
69 | |||
70 | return new self($httpClient); |
||
71 | } |
||
72 | |||
73 | /** |
||
74 | * Classify image |
||
75 | * |
||
76 | * @return \IBM\Watson\VisualRecognition\Api\Classify |
||
77 | */ |
||
78 | public function classify() |
||
79 | { |
||
80 | return new Api\Classify($this->httpClient, $this->hydrator, $this->requestBuilder); |
||
81 | } |
||
82 | } |
||
83 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.