Skip to content

Commit 3797edf

Browse files
committed
Add parameter and return type hints where possible
1 parent 98a4a2b commit 3797edf

2 files changed

Lines changed: 32 additions & 41 deletions

File tree

src/Authentication.php

Lines changed: 22 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -41,16 +41,14 @@ private function __construct(callable $getTokenRequestFunc)
4141
* @return Authentication
4242
*/
4343
public static function createClientCredentials(
44-
$clientId,
45-
$clientSecret,
46-
$refreshResource = 'token',
47-
$tokenResource = 'token'
44+
string $clientId,
45+
string $clientSecret,
46+
string $refreshResource = 'token',
47+
string $tokenResource = 'token'
4848
) : Authentication {
49-
Util::throwIfNotType(['string' => [$clientId, $clientSecret]], true);
50-
5149
$getTokenRequestFunc = function (
52-
$baseUrl,
53-
$refreshToken
50+
string $baseUrl,
51+
string $refreshToken = null
5452
) use (
5553
$clientId,
5654
$clientSecret,
@@ -92,18 +90,16 @@ public static function createClientCredentials(
9290
* @return Authentication
9391
*/
9492
public static function createOwnerCredentials(
95-
$clientId,
96-
$clientSecret,
97-
$username,
98-
$password,
99-
$refreshResource = 'token',
100-
$tokenResource = 'token'
93+
string $clientId,
94+
string $clientSecret,
95+
string $username,
96+
string $password,
97+
string $refreshResource = 'token',
98+
string $tokenResource = 'token'
10199
) : Authentication {
102-
Util::throwIfNotType(['string' => [$clientId, $clientSecret, $username, $password]], true);
103-
104100
$getTokenRequestFunc = function (
105-
$baseUrl,
106-
$refreshToken
101+
string $baseUrl,
102+
string $refreshToken = null
107103
) use (
108104
$clientId,
109105
$clientSecret,
@@ -166,16 +162,13 @@ public static function parseTokenResponse(ResponseInterface $response)
166162
/**
167163
* Creates a Request object for obtaining a new token from the API
168164
*
169-
* @param string $baseUrl The base url of the API
170-
* @param string $refreshToken The refresh token of the API
165+
* @param string $baseUrl The base url of the API
166+
* @param string|null $refreshToken The refresh token of the API
171167
*
172168
* @return RequestInterface
173169
*/
174-
public function getTokenRequest($baseUrl, $refreshToken) : RequestInterface
170+
public function getTokenRequest(string $baseUrl, string $refreshToken = null) : RequestInterface
175171
{
176-
Util::throwIfNotType(['string' => [$baseUrl]], true);
177-
Util::throwIfNotType(['string' => [$refreshToken]], true, true);
178-
179172
return call_user_func($this->getTokenRequestFunc, $baseUrl, $refreshToken);
180173
}
181174

@@ -192,11 +185,11 @@ public function getTokenRequest($baseUrl, $refreshToken) : RequestInterface
192185
* @return RequestInterface The built token refresh request
193186
*/
194187
private static function getRefreshTokenRequest(
195-
$baseUrl,
196-
$clientId,
197-
$clientSecret,
198-
$refreshResource,
199-
$refreshToken
188+
string $baseUrl,
189+
string $clientId,
190+
string $clientSecret,
191+
string $refreshResource,
192+
string $refreshToken
200193
) : RequestInterface {
201194
//NOTE client_id and client_secret are needed for Apigee but are not in the oauth2 spec
202195
$data = [

src/Collection.php

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,8 @@ final class Collection implements \Iterator, \Countable
7272
* @param string $resource name of API resource to request
7373
* @param array $filters key value pair array of search filters
7474
*/
75-
public function __construct(ClientInterface $client, $resource, array $filters = [])
75+
public function __construct(ClientInterface $client, string $resource, array $filters = [])
7676
{
77-
Util::throwIfNotType(['string' => [$resource]], true);
78-
7977
$this->client = $client;
8078
$this->resource = $resource;
8179
$this->filters = $filters;
@@ -85,9 +83,9 @@ public function __construct(ClientInterface $client, $resource, array $filters =
8583
/**
8684
* @see Countable::count()
8785
*
88-
* @return int
86+
* @return integer
8987
*/
90-
public function count()
88+
public function count() : int
9189
{
9290
if ($this->position === -1) {
9391
$this->next();
@@ -113,9 +111,9 @@ public function rewind()
113111
/**
114112
* @see Iterator::key()
115113
*
116-
* @return int
114+
* @return integer
117115
*/
118-
public function key()
116+
public function key() : int
119117
{
120118
if ($this->position === -1) {
121119
$this->next();
@@ -131,7 +129,7 @@ public function key()
131129
*
132130
* @return bool
133131
*/
134-
public function valid()
132+
public function valid() : bool
135133
{
136134
if ($this->position === -1) {
137135
$this->next();
@@ -172,7 +170,7 @@ public function next()
172170
*
173171
* @return array
174172
*/
175-
public function current()
173+
public function current() : array
176174
{
177175
if ($this->position === -1) {
178176
$this->next();
@@ -193,9 +191,9 @@ public function current()
193191
*
194192
* @param string $key The name of the field for which the values will be returned.
195193
*
196-
* @return iterable
194+
* @return \Iterator
197195
*/
198-
public function column($key)
196+
public function column(string $key) : \Iterator
199197
{
200198
foreach ($this as $item) {
201199
yield Util\Arrays::get($item, $key);
@@ -209,7 +207,7 @@ public function column($key)
209207
*
210208
* @return \Generator
211209
*/
212-
public function select(array $keys)
210+
public function select(array $keys) : \Iterator
213211
{
214212
foreach ($this as $item) {
215213
$result = array_fill_keys($keys, null);

0 commit comments

Comments
 (0)