14
14
abstract class AbstractApi
15
15
{
16
16
/**
17
- * @var \Imgur\ Client
17
+ * @var Client
18
18
*/
19
19
protected $ client ;
20
20
21
21
/**
22
- * @var \Imgur\Pager\ PagerInterface
22
+ * @var PagerInterface
23
23
*/
24
24
protected $ pager ;
25
25
@@ -31,16 +31,12 @@ public function __construct(Client $client, PagerInterface $pager = null)
31
31
32
32
/**
33
33
* Perform a GET request and return the parsed response.
34
- *
35
- * @param string $url
36
- *
37
- * @return array
38
34
*/
39
- public function get ($ url , $ parameters = [])
35
+ public function get (string $ url , array $ parameters = []): array
40
36
{
41
37
$ httpClient = $ this ->client ->getHttpClient ();
42
38
43
- if (! empty ( $ this ->pager ) ) {
39
+ if (null !== $ this ->pager ) {
44
40
$ parameters ['page ' ] = $ this ->pager ->getPage ();
45
41
$ parameters ['perPage ' ] = $ this ->pager ->getResultsPerPage ();
46
42
}
@@ -52,12 +48,8 @@ public function get($url, $parameters = [])
52
48
53
49
/**
54
50
* Perform a POST request and return the parsed response.
55
- *
56
- * @param string $url
57
- *
58
- * @return array
59
51
*/
60
- public function post ($ url , $ parameters = [])
52
+ public function post (string $ url , array $ parameters = []): array
61
53
{
62
54
$ httpClient = $ this ->client ->getHttpClient ();
63
55
@@ -68,12 +60,8 @@ public function post($url, $parameters = [])
68
60
69
61
/**
70
62
* Perform a PUT request and return the parsed response.
71
- *
72
- * @param string $url
73
- *
74
- * @return array
75
63
*/
76
- public function put ($ url , $ parameters = [])
64
+ public function put (string $ url , array $ parameters = []): array
77
65
{
78
66
$ httpClient = $ this ->client ->getHttpClient ();
79
67
@@ -84,12 +72,8 @@ public function put($url, $parameters = [])
84
72
85
73
/**
86
74
* Perform a DELETE request and return the parsed response.
87
- *
88
- * @param string $url
89
- *
90
- * @return array
91
75
*/
92
- public function delete ($ url , $ parameters = [])
76
+ public function delete (string $ url , array $ parameters = []): array
93
77
{
94
78
$ httpClient = $ this ->client ->getHttpClient ();
95
79
@@ -101,32 +85,29 @@ public function delete($url, $parameters = [])
101
85
/**
102
86
* Validate "sort" parameter and throw an exception if it's a bad value.
103
87
*
104
- * @param string $sort Input value
105
- * @param array $possibleValues
88
+ * @param string $sort Input value
106
89
*/
107
- protected function validateSortArgument ($ sort , $ possibleValues )
90
+ protected function validateSortArgument (string $ sort , array $ possibleValues ): void
108
91
{
109
92
$ this ->validateArgument ('Sort ' , $ sort , $ possibleValues );
110
93
}
111
94
112
95
/**
113
96
* Validate "window" parameter and throw an exception if it's a bad value.
114
97
*
115
- * @param string $window Input value
116
- * @param array $possibleValues
98
+ * @param string $window Input value
117
99
*/
118
- protected function validateWindowArgument ($ window , $ possibleValues )
100
+ protected function validateWindowArgument (string $ window , array $ possibleValues ): void
119
101
{
120
102
$ this ->validateArgument ('Window ' , $ window , $ possibleValues );
121
103
}
122
104
123
105
/**
124
106
* Validate "vote" parameter and throw an exception if it's a bad value.
125
107
*
126
- * @param string $vote Input value
127
- * @param array $possibleValues
108
+ * @param string $vote Input value
128
109
*/
129
- protected function validateVoteArgument ($ vote , $ possibleValues )
110
+ protected function validateVoteArgument (string $ vote , array $ possibleValues ): void
130
111
{
131
112
$ this ->validateArgument ('Vote ' , $ vote , $ possibleValues );
132
113
}
@@ -138,7 +119,7 @@ protected function validateVoteArgument($vote, $possibleValues)
138
119
* @param string $input Input value
139
120
* @param array $possibleValues Possible values for this argument
140
121
*/
141
- private function validateArgument ($ type , $ input , $ possibleValues )
122
+ private function validateArgument (string $ type , string $ input , array $ possibleValues ): void
142
123
{
143
124
if (!\in_array ($ input , $ possibleValues , true )) {
144
125
throw new InvalidArgumentException ($ type . ' parameter " ' . $ input . '" is wrong. Possible values are: ' . implode (', ' , $ possibleValues ));
0 commit comments