1010
1111class Guzzle
1212{
13-
1413 private Client $ client ;
1514
1615 private string $ error ;
17- private string $ errorCode ;
16+ private int $ errorCode ;
1817
1918 private string $ errorApi ;
2019
@@ -24,28 +23,30 @@ public function __construct(Authorization $authorization)
2423 {
2524 $ this ->client = new Client ([
2625 'base_uri ' => 'https://api.simpay.pl ' ,
27- 'headers ' => $ authorization ->getHeaders ()
26+ 'headers ' => $ authorization ->getHeaders (),
2827 ]);
2928 }
3029
30+ /**
31+ * @param array<string, mixed> $data
32+ * @param array<string, string> $headers
33+ *
34+ * @return false|object|Collection
35+ */
3136 public function request (string $ method , string $ uri , array $ data = [], array $ headers = [], bool $ collect = false )
3237 {
33-
3438 try {
35-
3639 $ response = $ this ->client ->request ($ method , $ uri , [
37- ($ method === ' GET ' ? 'query ' : 'json ' ) => $ data ,
40+ (' GET ' === $ method ? 'query ' : 'json ' ) => $ data ,
3841 'headers ' => $ headers ,
39- 'allow_redirects ' => false
42+ 'allow_redirects ' => false ,
4043 ]);
4144
4245 $ response = $ response ->getBody ()->getContents ();
4346 $ response = json_decode ($ response );
4447
4548 $ this ->data = $ response ;
46-
4749 } catch (ClientException $ exception ) {
48-
4950 $ response = $ exception ->getResponse ()->getBody ()->getContents ();
5051 $ json = json_decode ($ response );
5152
@@ -57,26 +58,22 @@ public function request(string $method, string $uri, array $data = [], array $he
5758 $ this ->errorCode = $ exception ->getCode ();
5859
5960 return false ;
60-
6161 } catch (GuzzleException $ exception ) {
62-
6362 $ this ->error = $ exception ->getMessage ();
6463 $ this ->errorCode = $ exception ->getCode ();
6564
6665 return false ;
67-
6866 }
6967
7068 return !$ collect ? $ response ->data : new Collection ($ response ->data );
71-
7269 }
7370
7471 public function getErrorMessage (): string
7572 {
7673 return $ this ->error ;
7774 }
7875
79- public function getErrorCode (): string
76+ public function getErrorCode (): int
8077 {
8178 return $ this ->errorCode ;
8279 }
@@ -86,9 +83,12 @@ public function getErrorApiMessage(): string
8683 return $ this ->errorApi ;
8784 }
8885
89- public function getPagination ()
86+ public function getPagination (): ? object
9087 {
88+ if (!isset ($ this ->data ->pagination )) {
89+ return null ;
90+ }
91+
9192 return $ this ->data ->pagination ;
9293 }
93-
94- }
94+ }
0 commit comments