44
55namespace Setono \PostNord \Client ;
66
7+ use const PHP_QUERY_RFC3986 ;
78use Psr \Http \Client \ClientExceptionInterface ;
89use Psr \Http \Client \ClientInterface as HttpClientInterface ;
910use Psr \Http \Message \RequestFactoryInterface ;
1617
1718final class Client implements ClientInterface
1819{
19- /**
20- * @var HttpClientInterface
21- */
20+ /** @var HttpClientInterface */
2221 private $ httpClient ;
2322
24- /**
25- * @var RequestFactoryInterface
26- */
23+ /** @var RequestFactoryInterface */
2724 private $ requestFactory ;
2825
29- /**
30- * @var StreamFactoryInterface
31- */
26+ /** @var StreamFactoryInterface */
3227 private $ streamFactory ;
3328
34- /**
35- * @var string
36- */
29+ /** @var string */
3730 private $ apiKey ;
3831
39- /**
40- * @var string
41- */
32+ /** @var string */
4233 private $ baseUrl ;
4334
4435 public function __construct (
@@ -56,11 +47,6 @@ public function __construct(
5647 }
5748
5849 /**
59- * @param string $endpoint
60- * @param array $params
61- *
62- * @return array
63- *
6450 * @throws ClientExceptionInterface
6551 * @throws JsonException
6652 * @throws StringsException
@@ -71,12 +57,6 @@ public function get(string $endpoint, array $params = []): array
7157 }
7258
7359 /**
74- * @param string $endpoint
75- * @param array $params
76- * @param array $body
77- *
78- * @return array
79- *
8060 * @throws ClientExceptionInterface
8161 * @throws JsonException
8262 * @throws StringsException
@@ -87,13 +67,6 @@ public function post(string $endpoint, array $params = [], array $body = []): ar
8767 }
8868
8969 /**
90- * @param string $method
91- * @param string $endpoint
92- * @param array $params
93- * @param array $body
94- *
95- * @return array
96- *
9770 * @throws ClientExceptionInterface
9871 * @throws JsonException
9972 * @throws StringsException
@@ -104,11 +77,11 @@ private function sendRequest(string $method, string $endpoint, array $params = [
10477 'apikey ' => $ this ->apiKey ,
10578 ], $ params );
10679
107- $ url = $ this ->baseUrl . '/ ' . $ endpoint. '? ' . http_build_query ($ params , '' , '& ' , PHP_QUERY_RFC3986 );
80+ $ url = $ this ->baseUrl . '/ ' . $ endpoint . '? ' . http_build_query ($ params , '' , '& ' , PHP_QUERY_RFC3986 );
10881
10982 $ request = $ this ->requestFactory ->createRequest ($ method , $ url );
11083
111- if (! empty ($ body )) {
84+ if (count ($ body ) > 0 ) {
11285 $ request = $ request ->withBody ($ this ->streamFactory ->createStream (json_encode ($ body )));
11386 }
11487
0 commit comments