Skip to content

Commit eec213c

Browse files
committed
feat: working on return types
1 parent c8f87b7 commit eec213c

File tree

3 files changed

+41
-37
lines changed

3 files changed

+41
-37
lines changed

.vscode/settings.json

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"intelephense.environment.phpVersion": "7.2.0"
3+
}

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
}
1111
],
1212
"require": {
13-
"php": ">=5.4.0"
13+
"php": ">=7.1.0"
1414
},
1515
"suggest": {
1616
"guzzlehttp/guzzle": "Guzzle ~4.0|~5.0|~6.0|~7.0"

src/Utils/Collection.php

+37-36
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,19 @@
22

33
namespace kamermans\OAuth2\Utils;
44

5+
use ArrayAccess;
6+
use Traversable;
7+
use IteratorAggregate;
8+
use Countable;
9+
use ArrayIterator;
10+
511
/**
612
* Key value pair collection object
713
*/
814
class Collection implements
9-
\ArrayAccess,
10-
\IteratorAggregate,
11-
\Countable
15+
ArrayAccess,
16+
IteratorAggregate,
17+
Countable
1218
{
1319

1420
/** @var array */
@@ -22,44 +28,37 @@ public function __construct(array $data = [])
2228
$this->data = $data;
2329
}
2430

25-
#[\ReturnTypeWillChange]
26-
public function getIterator()
31+
public function getIterator(): Traversable
2732
{
28-
return new \ArrayIterator($this->data);
33+
return new ArrayIterator($this->data);
2934
}
3035

31-
#[\ReturnTypeWillChange]
32-
public function offsetGet($offset)
36+
public function offsetGet($offset): ?string
3337
{
3438
return isset($this->data[$offset]) ? $this->data[$offset] : null;
3539
}
3640

37-
#[\ReturnTypeWillChange]
38-
public function offsetSet($offset, $value)
41+
public function offsetSet($offset, $value): void
3942
{
4043
$this->data[$offset] = $value;
4144
}
4245

43-
#[\ReturnTypeWillChange]
44-
public function offsetExists($offset)
46+
public function offsetExists($offset): bool
4547
{
4648
return isset($this->data[$offset]);
4749
}
4850

49-
#[\ReturnTypeWillChange]
50-
public function offsetUnset($offset)
51+
public function offsetUnset($offset): void
5152
{
5253
unset($this->data[$offset]);
5354
}
54-
55-
#[\ReturnTypeWillChange]
56-
public function toArray()
55+
56+
public function toArray(): array
5757
{
5858
return $this->data;
5959
}
6060

61-
#[\ReturnTypeWillChange]
62-
public function count()
61+
public function count(): int
6362
{
6463
return count($this->data);
6564
}
@@ -79,7 +78,8 @@ public static function fromConfig(
7978
array $config = [],
8079
array $defaults = [],
8180
array $required = []
82-
) {
81+
): Collection
82+
{
8383
$data = $config + $defaults;
8484

8585
if ($missing = array_diff($required, array_keys($data))) {
@@ -97,7 +97,7 @@ public static function fromConfig(
9797
*
9898
* @return Collection
9999
*/
100-
public function clear()
100+
public function clear(): Collection
101101
{
102102
$this->data = [];
103103

@@ -111,7 +111,7 @@ public function clear()
111111
*
112112
* @return mixed|null Value of the key or NULL
113113
*/
114-
public function get($key)
114+
public function get(string $key): string
115115
{
116116
return isset($this->data[$key]) ? $this->data[$key] : null;
117117
}
@@ -120,11 +120,11 @@ public function get($key)
120120
* Set a key value pair
121121
*
122122
* @param string $key Key to set
123-
* @param mixed $value Value to set
123+
* @param string $value Value to set
124124
*
125125
* @return Collection Returns a reference to the object
126126
*/
127-
public function set($key, $value)
127+
public function set(string $key, string $value): Collection
128128
{
129129
$this->data[$key] = $value;
130130

@@ -141,7 +141,7 @@ public function set($key, $value)
141141
*
142142
* @return Collection Returns a reference to the object.
143143
*/
144-
public function add($key, $value)
144+
public function add($key, $value): Collection
145145
{
146146
if (!array_key_exists($key, $this->data)) {
147147
$this->data[$key] = $value;
@@ -161,7 +161,7 @@ public function add($key, $value)
161161
*
162162
* @return Collection
163163
*/
164-
public function remove($key)
164+
public function remove(string $key): Collection
165165
{
166166
unset($this->data[$key]);
167167

@@ -173,7 +173,7 @@ public function remove($key)
173173
*
174174
* @return array
175175
*/
176-
public function getKeys()
176+
public function getKeys(): array
177177
{
178178
return array_keys($this->data);
179179
}
@@ -185,7 +185,7 @@ public function getKeys()
185185
*
186186
* @return bool
187187
*/
188-
public function hasKey($key)
188+
public function hasKey(string $key): bool
189189
{
190190
return array_key_exists($key, $this->data);
191191
}
@@ -195,12 +195,13 @@ public function hasKey($key)
195195
*
196196
* @param string $value Value to search for
197197
*
198-
* @return mixed Returns the key if the value was found FALSE if the value
198+
* @return mixed Returns the key if the value was found or NULL if the value
199199
* was not found.
200200
*/
201-
public function hasValue($value)
201+
public function hasValue(string $value): ?string
202202
{
203-
return array_search($value, $this->data, true);
203+
$val = array_search($value, $this->data, true);
204+
return $val === false ? null : $val;
204205
}
205206

206207
/**
@@ -210,7 +211,7 @@ public function hasValue($value)
210211
*
211212
* @return Collection Returns a reference to the object
212213
*/
213-
public function replace(array $data)
214+
public function replace(array $data): Collection
214215
{
215216
$this->data = $data;
216217

@@ -224,7 +225,7 @@ public function replace(array $data)
224225
*
225226
* @return Collection Returns a reference to the object.
226227
*/
227-
public function merge($data)
228+
public function merge(Traversable $data): Collection
228229
{
229230
foreach ($data as $key => $value) {
230231
$this->add($key, $value);
@@ -241,7 +242,7 @@ public function merge($data)
241242
*
242243
* @return self
243244
*/
244-
public function overwriteWith($data)
245+
public function overwriteWith(Traversable $data): Collection
245246
{
246247
if (is_array($data)) {
247248
$this->data = $data + $this->data;
@@ -272,7 +273,7 @@ public function overwriteWith($data)
272273
*
273274
* @return Collection
274275
*/
275-
public function map(callable $closure, array $context = [])
276+
public function map(callable $closure, array $context = []): Collection
276277
{
277278
$collection = new static();
278279
foreach ($this as $key => $value) {
@@ -295,7 +296,7 @@ public function map(callable $closure, array $context = [])
295296
*
296297
* @return Collection
297298
*/
298-
public function filter(callable $closure)
299+
public function filter(callable $closure): Collection
299300
{
300301
$collection = new static();
301302
foreach ($this->data as $key => $value) {

0 commit comments

Comments
 (0)