1 | <?php |
||
8 | class WorkEtcClient |
||
9 | { |
||
10 | /** |
||
11 | * @var \WorkEtcClient\HttpInterface |
||
12 | */ |
||
13 | protected $httpClient; |
||
14 | |||
15 | /** |
||
16 | * @var string |
||
17 | */ |
||
18 | protected $domain = null; |
||
19 | |||
20 | /** |
||
21 | * @var string |
||
22 | */ |
||
23 | protected $url = null; |
||
24 | |||
25 | /** |
||
26 | * @var string |
||
27 | */ |
||
28 | protected $sessionKey = null; |
||
29 | |||
30 | /** |
||
31 | * @param \WorkEtcClient\HttpInterface |
||
32 | */ |
||
33 | public function __construct(HttpInterface $httpClient) |
||
37 | |||
38 | /** |
||
39 | * Connect to WORK[etc] and return the connection. |
||
40 | * |
||
41 | * @param string $domain |
||
42 | * @param string $email |
||
43 | * @param string $password |
||
44 | * |
||
45 | * @return \WorkEtcClient\WorkEtcClient |
||
46 | */ |
||
47 | public static function connect(string $domain, string $email, string $password): WorkEtcClient |
||
55 | |||
56 | /** |
||
57 | * Authenticate into WORK[etc]. |
||
58 | * |
||
59 | * @param string $domain |
||
60 | * @param string $email |
||
61 | * @param string $password |
||
62 | * |
||
63 | * @return void |
||
64 | * |
||
65 | * @throws \WorkEtcClient\WorkEtcException |
||
66 | */ |
||
67 | public function login(string $domain, string $email, string $password) |
||
78 | |||
79 | /** |
||
80 | * @param string $domain |
||
81 | * |
||
82 | * @return void |
||
83 | */ |
||
84 | protected function registerDomain(string $domain) |
||
90 | |||
91 | /** |
||
92 | * Invoke the given method and return the result. |
||
93 | * |
||
94 | * @param string $endpoint |
||
95 | * @param array $params |
||
96 | * |
||
97 | * @return array|string |
||
98 | * |
||
99 | * @throws \WorkEtcClient\WorkEtcException |
||
100 | */ |
||
101 | public function invoke(string $endpoint, array $params = []) |
||
115 | |||
116 | /** |
||
117 | * Build the URL from the registered domain and the endpoint. |
||
118 | * |
||
119 | * @param string $endpoint |
||
120 | * |
||
121 | * @return string |
||
122 | */ |
||
123 | protected function buildUrl(string $endpoint): string |
||
131 | |||
132 | /** |
||
133 | * Check if the WORK[etc] response had errors and attempts to parse them if |
||
134 | * so. |
||
135 | * |
||
136 | * @param array $response |
||
137 | * |
||
138 | * @return void |
||
139 | * |
||
140 | * @throws \WorkEtcClient\WorkEtcException if the HTTP response code is 400 or above. |
||
141 | */ |
||
142 | protected function checkErrors(array $response) |
||
150 | } |
||
151 |
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.