1515
1616use Bitbucket \Exception \InvalidArgumentException ;
1717use Bitbucket \HttpClient \Message \ResponseMediator ;
18+ use Bitbucket \JsonArray ;
1819use Http \Client \Common \HttpMethodsClientInterface ;
1920
2021/**
@@ -125,7 +126,7 @@ protected function pureGet(string $path, array $params = [], array $headers = []
125126 $ params ['pagelen ' ] = $ this ->perPage ;
126127 }
127128
128- if ($ params ) {
129+ if (count ( $ params) === 0 ) {
129130 $ path .= '? ' .http_build_query ($ params );
130131 }
131132
@@ -147,7 +148,7 @@ protected function post(string $path, array $params = [], array $headers = [])
147148 {
148149 $ body = self ::createJsonBody ($ params );
149150
150- if ($ body ) {
151+ if ($ body !== null ) {
151152 $ headers = self ::addJsonContentType ($ headers );
152153 }
153154
@@ -187,7 +188,7 @@ protected function put(string $path, array $params = [], array $headers = [])
187188 {
188189 $ body = self ::createJsonBody ($ params );
189190
190- if ($ body ) {
191+ if ($ body !== null ) {
191192 $ headers = self ::addJsonContentType ($ headers );
192193 }
193194
@@ -227,7 +228,7 @@ protected function delete(string $path, array $params = [], array $headers = [])
227228 {
228229 $ body = self ::createJsonBody ($ params );
229230
230- if ($ body ) {
231+ if ($ body !== null ) {
231232 $ headers = self ::addJsonContentType ($ headers );
232233 }
233234
@@ -255,16 +256,16 @@ protected function deleteRaw(string $path, $body = null, array $headers = [])
255256 /**
256257 * Build a URL path from the given parts.
257258 *
258- * @param string[] $parts
259+ * @param string ... $parts
259260 *
260261 * @throws \Bitbucket\Exception\InvalidArgumentException
261262 *
262263 * @return string
263264 */
264265 protected static function buildPath (string ...$ parts )
265266 {
266- $ parts = array_map (function (string $ part ) {
267- if (! $ part ) {
267+ $ parts = array_map (function (string $ part ) {
268+ if ($ part === '' ) {
268269 throw new InvalidArgumentException ('Missing required parameter. ' );
269270 }
270271
@@ -295,17 +296,19 @@ private static function computePath(string $path)
295296 */
296297 private static function createJsonBody (array $ params )
297298 {
298- if ($ params ) {
299- return json_encode ($ params );
299+ if (count ( $ params) === 0 ) {
300+ return JsonArray:: encode ($ params );
300301 }
302+
303+ return null ;
301304 }
302305
303306 /**
304307 * Add the JSON content type to the headers if one is not already present.
305308 *
306- * @param array $headers
309+ * @param array<string,string> $headers
307310 *
308- * @return array
311+ * @return array<string,string>
309312 */
310313 private static function addJsonContentType (array $ headers )
311314 {
0 commit comments