1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Happyr\ApiClient; |
4
|
|
|
|
5
|
|
|
use Happyr\ApiClient\Hydrator\ModelHydrator; |
6
|
|
|
use Happyr\ApiClient\Hydrator\Hydrator; |
7
|
|
|
use Http\Client\HttpClient; |
8
|
|
|
use Http\Discovery\MessageFactoryDiscovery; |
9
|
|
|
use Http\Message\RequestFactory; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* @author Tobias Nyholm <[email protected]> |
13
|
|
|
*/ |
14
|
|
|
final class HappyrClient |
15
|
|
|
{ |
16
|
|
|
/** |
17
|
|
|
* @var HttpClient |
18
|
|
|
*/ |
19
|
|
|
private $httpClient; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @var Hydrator |
23
|
|
|
*/ |
24
|
|
|
private $hydrator; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @var RequestFactory |
28
|
|
|
*/ |
29
|
|
|
private $requestFactory; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* The constructor accepts already configured HTTP clients. |
33
|
|
|
* Use the configure method to pass a configuration to the Client and create an HTTP Client. |
34
|
|
|
* |
35
|
|
|
* @param HttpClient $httpClient |
36
|
|
|
* @param Hydrator|null $hydrator |
37
|
|
|
* @param RequestFactory|null $requestFactory |
38
|
|
|
*/ |
39
|
|
|
public function __construct( |
40
|
|
|
HttpClient $httpClient, |
41
|
|
|
Hydrator $hydrator = null, |
42
|
|
|
RequestFactory $requestFactory = null |
43
|
|
|
) { |
44
|
|
|
$this->httpClient = $httpClient; |
45
|
|
|
$this->hydrator = $hydrator ?: new ModelHydrator(); |
46
|
|
|
$this->requestFactory = $requestFactory ?: MessageFactoryDiscovery::find(); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @param HttpClientConfigurator $httpClientConfigurator |
51
|
|
|
* @param Hydrator|null $hydrator |
52
|
|
|
* @param RequestFactory|null $requestFactory |
53
|
|
|
* |
54
|
|
|
* @return HappyrClient |
55
|
|
|
*/ |
56
|
|
|
public static function configure( |
57
|
|
|
HttpClientConfigurator $httpClientConfigurator, |
58
|
|
|
Hydrator $hydrator = null, |
59
|
|
|
RequestFactory $requestFactory = null |
60
|
|
|
) { |
61
|
|
|
$httpClient = $httpClientConfigurator->createConfiguredClient(); |
62
|
|
|
|
63
|
|
|
return new self($httpClient, $hydrator, $requestFactory); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @param string $apiKey |
|
|
|
|
68
|
|
|
* |
69
|
|
|
* @return HappyrClient |
70
|
|
|
*/ |
71
|
|
|
public static function create($apiUser, $apiPassword) |
72
|
|
|
{ |
73
|
|
|
$httpClientConfigurator = (new HttpClientConfigurator())->setApiCredentials($apiUser, $apiPassword); |
74
|
|
|
|
75
|
|
|
return self::configure($httpClientConfigurator); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* @return Api\Interview |
80
|
|
|
*/ |
81
|
|
|
public function interview() |
82
|
|
|
{ |
83
|
|
|
return new Api\Interview($this->httpClient, $this->hydrator, $this->requestFactory); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* @return Api\Dimension |
88
|
|
|
*/ |
89
|
|
|
public function dimensions() |
90
|
|
|
{ |
91
|
|
|
return new Api\Dimension($this->httpClient, $this->hydrator, $this->requestFactory); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* @return Api\Match |
96
|
|
|
*/ |
97
|
|
|
public function match() |
98
|
|
|
{ |
99
|
|
|
return new Api\Match($this->httpClient, $this->hydrator, $this->requestFactory); |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* @return Api\Norm |
104
|
|
|
*/ |
105
|
|
|
public function norm() |
106
|
|
|
{ |
107
|
|
|
return new Api\Norm($this->httpClient, $this->hydrator, $this->requestFactory); |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* @return Api\ProfilePattern |
112
|
|
|
*/ |
113
|
|
|
public function profilePattern() |
114
|
|
|
{ |
115
|
|
|
return new Api\ProfilePattern($this->httpClient, $this->hydrator, $this->requestFactory); |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* @return Api\Statement |
120
|
|
|
*/ |
121
|
|
|
public function statement() |
122
|
|
|
{ |
123
|
|
|
return new Api\Statement($this->httpClient, $this->hydrator, $this->requestFactory); |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
/** |
127
|
|
|
* @return Api\UserManagement |
128
|
|
|
*/ |
129
|
|
|
public function userManagement() |
130
|
|
|
{ |
131
|
|
|
return new Api\UserManagement($this->httpClient, $this->hydrator, $this->requestFactory); |
132
|
|
|
} |
133
|
|
|
} |
134
|
|
|
|
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italy
is not defined by the methodfinale(...)
.The most likely cause is that the parameter was removed, but the annotation was not.