@@ -14,28 +14,28 @@ class Client
1414 const METHOD_CONNECT = ' CONNECT' ;
1515 const METHOD_TRACE = ' TRACE' ;
1616
17- const CHUNK_SIZE = 5 * 1024 * 1024 ;
17+ const CHUNK_SIZE = 5 * 1024 * 1024 ;
1818
1919 /**
2020 * Is Self Signed Certificates Allowed?
2121 *
2222 * @var bool
2323 */
24- protected $selfSigned = false ;
24+ protected bool $selfSigned = false ;
2525
2626 /**
2727 * Service host name
2828 *
2929 * @var string
3030 */
31- protected $endpoint = ' {{spec.endpoint}}' ;
31+ protected string $endpoint = ' {{spec.endpoint}}' ;
3232
3333 /**
3434 * Global Headers
3535 *
3636 * @var array
3737 */
38- protected $headers = [
38+ protected array $headers = [
3939 ' content-type' => ' ' ,
4040 ' user-agent' => ' {{spec.title | caseUcfirst}}{{ language.name | caseUcfirst }}SDK/{{ sdk.version }} ({{deviceInfo}})' ,
4141 ' x-sdk-name' => ' {{ sdk.name }}' ,
@@ -45,7 +45,7 @@ class Client
4545 ];
4646
4747 /**
48- * SDK constructor.
48+ * Client constructor.
4949 */
5050 public function __construct ()
5151 {
@@ -66,7 +66,7 @@ class Client
6666 *
6767 * @return Client
6868 */
69- public function set {{header . key | caseUcfirst }}($value )
69+ public function set {{header . key | caseUcfirst }}(string $value ): Client
7070 {
7171 $this -> addHeader(' {{header.name}}' , $value );
7272
@@ -79,7 +79,7 @@ class Client
7979 * @param bool $status
8080 * @return $this
8181 */
82- public function setSelfSigned ($status = true )
82+ public function setSelfSigned (bool $status = true ): Client
8383 {
8484 $this -> selfSigned = $status ;
8585
@@ -90,7 +90,7 @@ class Client
9090 * @param $endpoint
9191 * @return $this
9292 */
93- public function setEndpoint ($endpoint )
93+ public function setEndpoint (string $endpoint ): Client
9494 {
9595 $this -> endpoint = $endpoint ;
9696
@@ -101,7 +101,7 @@ class Client
101101 * @param $key
102102 * @param $value
103103 */
104- public function addHeader ($key , $value )
104+ public function addHeader (string $key , string $value ): Client
105105 {
106106 $this -> headers [strtolower ($key )] = $value ;
107107
@@ -120,7 +120,13 @@ class Client
120120 * @return array|string
121121 * @throws {{spec.title | caseUcfirst}}Exception
122122 */
123- public function call ($method , $path = ' ' , $headers = array (), array $params = array (), ? string $responseType = null )
123+ public function call (
124+ string $method ,
125+ string $path = ' ' ,
126+ array $headers = [],
127+ array $params = [],
128+ ? string $responseType = null
129+ )
124130 {
125131 $headers = array_merge ($this -> headers , $headers );
126132 $ch = curl_init ($this -> endpoint . $path . (($method == self :: METHOD_GET && ! empty ($params )) ? ' ?' . http_build_query ($params ) : ' ' ));
@@ -191,14 +197,14 @@ class Client
191197 }
192198
193199 if (curl_errno ($ch )) {
194- throw new {{spec . title | caseUcfirst }}Exception(curl_error ($ch ), $responseStatus , $responseBody );
200+ throw new {{spec . title | caseUcfirst }}Exception(curl_error ($ch ), $responseStatus , $responseBody [ ' type ' ] ?? ' ' , $responseBody );
195201 }
196202
197203 curl_close ($ch );
198204
199205 if ($responseStatus >= 400 ) {
200206 if (is_array ($responseBody )) {
201- throw new {{spec . title | caseUcfirst }}Exception($responseBody [' message' ], $responseStatus , $responseBody [' type' ] ?? ' ' , $responseBody );
207+ throw new {{spec . title | caseUcfirst }}Exception($responseBody [' message' ], $responseStatus , $responseBody [' type' ] ?? ' ' , json_encode ( $responseBody ) );
202208 } else {
203209 throw new {{spec . title | caseUcfirst }}Exception($responseBody , $responseStatus );
204210 }
@@ -218,7 +224,7 @@ class Client
218224 * @param string $prefix
219225 * @return array
220226 */
221- protected function flatten (array $data , $prefix = ' ' ) {
227+ protected function flatten (array $data , string $prefix = ' ' ): array {
222228 $output = [];
223229
224230 foreach ($data as $key => $value ) {
0 commit comments