Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Static return types, min ver PHP 7.1 #60

Merged
merged 2 commits into from
May 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"intelephense.environment.phpVersion": "7.2.0"
}
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
}
],
"require": {
"php": ">=5.4.0"
"php": ">=7.1.0"
},
"suggest": {
"guzzlehttp/guzzle": "Guzzle ~4.0|~5.0|~6.0|~7.0"
Expand Down
1 change: 0 additions & 1 deletion guzzle_environments/run_tests_docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ function run_tests()
}

if [[ $TEST = "all" ]]; then
run_tests 4 php5.6
run_tests 5 php7.4
run_tests 6 php7.4
run_tests 7 php7.4
Expand Down
73 changes: 37 additions & 36 deletions src/Utils/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,19 @@

namespace kamermans\OAuth2\Utils;

use ArrayAccess;
use Traversable;
use IteratorAggregate;
use Countable;
use ArrayIterator;

/**
* Key value pair collection object
*/
class Collection implements
\ArrayAccess,
\IteratorAggregate,
\Countable
ArrayAccess,
IteratorAggregate,
Countable
{

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

#[\ReturnTypeWillChange]
public function getIterator()
public function getIterator(): Traversable
{
return new \ArrayIterator($this->data);
return new ArrayIterator($this->data);
}

#[\ReturnTypeWillChange]
public function offsetGet($offset)
public function offsetGet($offset): ?string
{
return isset($this->data[$offset]) ? $this->data[$offset] : null;
}

#[\ReturnTypeWillChange]
public function offsetSet($offset, $value)
public function offsetSet($offset, $value): void
{
$this->data[$offset] = $value;
}

#[\ReturnTypeWillChange]
public function offsetExists($offset)
public function offsetExists($offset): bool
{
return isset($this->data[$offset]);
}

#[\ReturnTypeWillChange]
public function offsetUnset($offset)
public function offsetUnset($offset): void
{
unset($this->data[$offset]);
}

#[\ReturnTypeWillChange]
public function toArray()

public function toArray(): array
{
return $this->data;
}

#[\ReturnTypeWillChange]
public function count()
public function count(): int
{
return count($this->data);
}
Expand All @@ -79,7 +78,8 @@ public static function fromConfig(
array $config = [],
array $defaults = [],
array $required = []
) {
): Collection
{
$data = $config + $defaults;

if ($missing = array_diff($required, array_keys($data))) {
Expand All @@ -97,7 +97,7 @@ public static function fromConfig(
*
* @return Collection
*/
public function clear()
public function clear(): Collection
{
$this->data = [];

Expand All @@ -111,7 +111,7 @@ public function clear()
*
* @return mixed|null Value of the key or NULL
*/
public function get($key)
public function get(string $key): string
{
return isset($this->data[$key]) ? $this->data[$key] : null;
}
Expand All @@ -120,11 +120,11 @@ public function get($key)
* Set a key value pair
*
* @param string $key Key to set
* @param mixed $value Value to set
* @param string $value Value to set
*
* @return Collection Returns a reference to the object
*/
public function set($key, $value)
public function set(string $key, string $value): Collection
{
$this->data[$key] = $value;

Expand All @@ -141,7 +141,7 @@ public function set($key, $value)
*
* @return Collection Returns a reference to the object.
*/
public function add($key, $value)
public function add($key, $value): Collection
{
if (!array_key_exists($key, $this->data)) {
$this->data[$key] = $value;
Expand All @@ -161,7 +161,7 @@ public function add($key, $value)
*
* @return Collection
*/
public function remove($key)
public function remove(string $key): Collection
{
unset($this->data[$key]);

Expand All @@ -173,7 +173,7 @@ public function remove($key)
*
* @return array
*/
public function getKeys()
public function getKeys(): array
{
return array_keys($this->data);
}
Expand All @@ -185,7 +185,7 @@ public function getKeys()
*
* @return bool
*/
public function hasKey($key)
public function hasKey(string $key): bool
{
return array_key_exists($key, $this->data);
}
Expand All @@ -195,12 +195,13 @@ public function hasKey($key)
*
* @param string $value Value to search for
*
* @return mixed Returns the key if the value was found FALSE if the value
* @return mixed Returns the key if the value was found or NULL if the value
* was not found.
*/
public function hasValue($value)
public function hasValue(string $value): ?string
{
return array_search($value, $this->data, true);
$val = array_search($value, $this->data, true);
return $val === false ? null : $val;
}

/**
Expand All @@ -210,7 +211,7 @@ public function hasValue($value)
*
* @return Collection Returns a reference to the object
*/
public function replace(array $data)
public function replace(array $data): Collection
{
$this->data = $data;

Expand All @@ -224,7 +225,7 @@ public function replace(array $data)
*
* @return Collection Returns a reference to the object.
*/
public function merge($data)
public function merge(Traversable $data): Collection
{
foreach ($data as $key => $value) {
$this->add($key, $value);
Expand All @@ -241,7 +242,7 @@ public function merge($data)
*
* @return self
*/
public function overwriteWith($data)
public function overwriteWith(Traversable $data): Collection
{
if (is_array($data)) {
$this->data = $data + $this->data;
Expand Down Expand Up @@ -272,7 +273,7 @@ public function overwriteWith($data)
*
* @return Collection
*/
public function map(callable $closure, array $context = [])
public function map(callable $closure, array $context = []): Collection
{
$collection = new static();
foreach ($this as $key => $value) {
Expand All @@ -295,7 +296,7 @@ public function map(callable $closure, array $context = [])
*
* @return Collection
*/
public function filter(callable $closure)
public function filter(callable $closure): Collection
{
$collection = new static();
foreach ($this->data as $key => $value) {
Expand Down
Loading