33namespace Larva \Pusher ;
44
55use Exception ;
6- use Larva \Forge \Exceptions \FailedActionException ;
7- use Larva \Forge \Exceptions \NotFoundException ;
8- use Larva \Forge \Exceptions \RateLimitExceededException ;
9- use Larva \Forge \Exceptions \TimeoutException ;
10- use Larva \Forge \Exceptions \ValidationException ;
6+ use Larva \Pusher \Exceptions \FailedActionException ;
7+ use Larva \Pusher \Exceptions \NotFoundException ;
8+ use Larva \Pusher \Exceptions \RateLimitExceededException ;
9+ use Larva \Pusher \Exceptions \TimeoutException ;
10+ use Larva \Pusher \Exceptions \ValidationException ;
1111use Psr \Http \Message \ResponseInterface ;
1212
1313trait MakesHttpRequests
1414{
1515 /**
1616 * Make a GET request to Forge servers and return the response.
1717 *
18- * @param string $uri
18+ * @param string $uri
1919 * @return mixed
2020 */
21- public function get ($ uri )
21+ public function get (string $ uri )
2222 {
2323 return $ this ->request ('GET ' , $ uri );
2424 }
2525
2626 /**
2727 * Make a POST request to Forge servers and return the response.
2828 *
29- * @param string $uri
30- * @param array $payload
29+ * @param string $uri
30+ * @param array $payload
3131 * @return mixed
3232 */
33- public function post ($ uri , array $ payload = [])
33+ public function post (string $ uri , array $ payload = [])
3434 {
3535 return $ this ->request ('POST ' , $ uri , $ payload );
3636 }
3737
3838 /**
3939 * Make a PUT request to Forge servers and return the response.
4040 *
41- * @param string $uri
42- * @param array $payload
41+ * @param string $uri
42+ * @param array $payload
4343 * @return mixed
4444 */
45- public function put ($ uri , array $ payload = [])
45+ public function put (string $ uri , array $ payload = [])
4646 {
4747 return $ this ->request ('PUT ' , $ uri , $ payload );
4848 }
4949
5050 /**
5151 * Make a DELETE request to Forge servers and return the response.
5252 *
53- * @param string $uri
54- * @param array $payload
53+ * @param string $uri
54+ * @param array $payload
5555 * @return mixed
5656 */
57- public function delete ($ uri , array $ payload = [])
57+ public function delete (string $ uri , array $ payload = [])
5858 {
5959 return $ this ->request ('DELETE ' , $ uri , $ payload );
6060 }
6161
6262 /**
6363 * Make request to Forge servers and return the response.
6464 *
65- * @param string $verb
66- * @param string $uri
67- * @param array $payload
65+ * @param string $verb
66+ * @param string $uri
67+ * @param array $payload
6868 * @return mixed
6969 */
70- protected function request ($ verb , $ uri , array $ payload = [])
70+ protected function request (string $ verb , string $ uri , array $ payload = [])
7171 {
7272 if (isset ($ payload ['json ' ])) {
7373 $ payload = ['json ' => $ payload ['json ' ]];
@@ -83,57 +83,57 @@ protected function request($verb, $uri, array $payload = [])
8383 return $ this ->handleRequestError ($ response );
8484 }
8585
86- $ responseBody = (string ) $ response ->getBody ();
86+ $ responseBody = (string )$ response ->getBody ();
8787
8888 return json_decode ($ responseBody , true ) ?: $ responseBody ;
8989 }
9090
9191 /**
9292 * Handle the request error.
9393 *
94- * @param \Psr\Http\Message\ResponseInterface $response
94+ * @param \Psr\Http\Message\ResponseInterface $response
9595 * @return void
9696 *
9797 * @throws \Exception
98- * @throws \Larva\Forge \Exceptions\FailedActionException
99- * @throws \Larva\Forge \Exceptions\NotFoundException
100- * @throws \Larva\Forge \Exceptions\ValidationException
101- * @throws \Larva\Forge \Exceptions\RateLimitExceededException
98+ * @throws \Larva\Pusher \Exceptions\FailedActionException
99+ * @throws \Larva\Pusher \Exceptions\NotFoundException
100+ * @throws \Larva\Pusher \Exceptions\ValidationException
101+ * @throws \Larva\Pusher \Exceptions\RateLimitExceededException
102102 */
103103 protected function handleRequestError (ResponseInterface $ response )
104104 {
105105 if ($ response ->getStatusCode () == 422 ) {
106- throw new ValidationException (json_decode ((string ) $ response ->getBody (), true ));
106+ throw new ValidationException (json_decode ((string )$ response ->getBody (), true ));
107107 }
108108
109109 if ($ response ->getStatusCode () == 404 ) {
110110 throw new NotFoundException ();
111111 }
112112
113113 if ($ response ->getStatusCode () == 400 ) {
114- throw new FailedActionException ((string ) $ response ->getBody ());
114+ throw new FailedActionException ((string )$ response ->getBody ());
115115 }
116116
117117 if ($ response ->getStatusCode () === 429 ) {
118118 throw new RateLimitExceededException (
119119 $ response ->hasHeader ('x-ratelimit-reset ' )
120- ? (int ) $ response ->getHeader ('x-ratelimit-reset ' )[0 ]
120+ ? (int )$ response ->getHeader ('x-ratelimit-reset ' )[0 ]
121121 : null
122122 );
123123 }
124124
125- throw new Exception ((string ) $ response ->getBody ());
125+ throw new Exception ((string )$ response ->getBody ());
126126 }
127127
128128 /**
129129 * Retry the callback or fail after x seconds.
130130 *
131- * @param int $timeout
132- * @param callable $callback
133- * @param int $sleep
131+ * @param int $timeout
132+ * @param callable $callback
133+ * @param int $sleep
134134 * @return mixed
135135 *
136- * @throws \Larva\Forge \Exceptions\TimeoutException
136+ * @throws \Larva\Pusher \Exceptions\TimeoutException
137137 */
138138 public function retry ($ timeout , $ callback , $ sleep = 5 )
139139 {
@@ -155,7 +155,7 @@ public function retry($timeout, $callback, $sleep = 5)
155155 $ output = [];
156156 }
157157
158- if (! is_array ($ output )) {
158+ if (!is_array ($ output )) {
159159 $ output = [$ output ];
160160 }
161161
0 commit comments