← All changes
|
includes/sdk/google/ramsey/collection/src/AbstractArray.php
+18
-52
1.2.13
→
1.4.1
View file →
| @@ -9,15 +9,13 @@ | ||
| 9 | 9 | * @copyright Copyright (c) Ben Ramsey <ben@benramsey.com> |
| 10 | 10 | * @license http://opensource.org/licenses/MIT MIT |
| 11 | 11 | */ |
| 12 | 12 | declare (strict_types=1); |
| 13 | -namespace Dudlewebs\WPMCS\Ramsey\Collection; | |
| 13 | +namespace Dudlewebs\WPMCS\GCP\Ramsey\Collection; | |
| 14 | 14 | |
| 15 | 15 | use ArrayIterator; |
| 16 | 16 | use Traversable; |
| 17 | 17 | use function count; |
| 18 | -use function serialize; | |
| 19 | -use function unserialize; | |
| 20 | 18 | /** |
| 21 | 19 | * This class provides a basic implementation of `ArrayInterface`, to minimize |
| 22 | 20 | * the effort required to implement this interface. |
| 23 | 21 | * |
| @@ -38,9 +36,9 @@ | ||
| 38 | 36 | * @param array<array-key, T> $data The initial items to add to this array. |
| 39 | 37 | */ |
| 40 | 38 | public function __construct(array $data = []) |
| 41 | 39 | { |
| 42 | - // Invoke offsetSet() for each value added; in this way, sub-classes | |
| 40 | + // Invoke offsetSet() for each value added; in this way, subclasses | |
| 43 | 41 | // may provide additional logic about values added to the array object. |
| 44 | 42 | foreach ($data as $key => $value) { |
| 45 | 43 | $this[$key] = $value; |
| 46 | 44 | } |
| @@ -51,9 +49,9 @@ | ||
| 51 | 49 | * @link http://php.net/manual/en/iteratoraggregate.getiterator.php IteratorAggregate::getIterator() |
| 52 | 50 | * |
| 53 | 51 | * @return Traversable<array-key, T> |
| 54 | 52 | */ |
| 55 | - public function getIterator(): Traversable | |
| 53 | + public function getIterator() : Traversable | |
| 56 | 54 | { |
| 57 | 55 | return new ArrayIterator($this->data); |
| 58 | 56 | } |
| 59 | 57 | /** |
| @@ -62,9 +60,9 @@ | ||
| 62 | 60 | * @link http://php.net/manual/en/arrayaccess.offsetexists.php ArrayAccess::offsetExists() |
| 63 | 61 | * |
| 64 | 62 | * @param array-key $offset The offset to check. |
| 65 | 63 | */ |
| 66 | - public function offsetExists($offset): bool | |
| 64 | + public function offsetExists(mixed $offset) : bool | |
| 67 | 65 | { |
| 68 | 66 | return isset($this->data[$offset]); |
| 69 | 67 | } |
| 70 | 68 | /** |
| @@ -73,15 +71,14 @@ | ||
| 73 | 71 | * @link http://php.net/manual/en/arrayaccess.offsetget.php ArrayAccess::offsetGet() |
| 74 | 72 | * |
| 75 | 73 | * @param array-key $offset The offset for which a value should be returned. |
| 76 | 74 | * |
| 77 | - * @return T|null the value stored at the offset, or null if the offset | |
| 75 | + * @return T the value stored at the offset, or null if the offset | |
| 78 | 76 | * does not exist. |
| 79 | 77 | */ |
| 80 | - #[\ReturnTypeWillChange] | |
| 81 | - public function offsetGet($offset) | |
| 78 | + public function offsetGet(mixed $offset) : mixed | |
| 82 | 79 | { |
| 83 | - return $this->data[$offset] ?? null; | |
| 80 | + return $this->data[$offset]; | |
| 84 | 81 | } |
| 85 | 82 | /** |
| 86 | 83 | * Sets the given value to the given offset in the array. |
| 87 | 84 | * |
| @@ -86,14 +83,13 @@ | ||
| 86 | 83 | * Sets the given value to the given offset in the array. |
| 87 | 84 | * |
| 88 | 85 | * @link http://php.net/manual/en/arrayaccess.offsetset.php ArrayAccess::offsetSet() |
| 89 | 86 | * |
| 90 | - * @param array-key|null $offset The offset to set. If `null`, the value may be | |
| 91 | - * set at a numerically-indexed offset. | |
| 87 | + * @param array-key | null $offset The offset to set. If `null`, the value | |
| 88 | + * may be set at a numerically-indexed offset. | |
| 92 | 89 | * @param T $value The value to set at the given offset. |
| 93 | 90 | */ |
| 94 | - // phpcs:ignore SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint | |
| 95 | - public function offsetSet($offset, $value): void | |
| 91 | + public function offsetSet(mixed $offset, mixed $value) : void | |
| 96 | 92 | { |
| 97 | 93 | if ($offset === null) { |
| 98 | 94 | $this->data[] = $value; |
| 99 | 95 | } else { |
| @@ -106,26 +102,13 @@ | ||
| 106 | 102 | * @link http://php.net/manual/en/arrayaccess.offsetunset.php ArrayAccess::offsetUnset() |
| 107 | 103 | * |
| 108 | 104 | * @param array-key $offset The offset to remove from the array. |
| 109 | 105 | */ |
| 110 | - public function offsetUnset($offset): void | |
| 106 | + public function offsetUnset(mixed $offset) : void | |
| 111 | 107 | { |
| 112 | 108 | unset($this->data[$offset]); |
| 113 | 109 | } |
| 114 | 110 | /** |
| 115 | - * Returns a serialized string representation of this array object. | |
| 116 | - * | |
| 117 | - * @deprecated The Serializable interface will go away in PHP 9. | |
| 118 | - * | |
| 119 | - * @link http://php.net/manual/en/serializable.serialize.php Serializable::serialize() | |
| 120 | - * | |
| 121 | - * @return string a PHP serialized string. | |
| 122 | - */ | |
| 123 | - public function serialize(): string | |
| 124 | - { | |
| 125 | - return serialize($this->data); | |
| 126 | - } | |
| 127 | - /** | |
| 128 | 111 | * Returns data suitable for PHP serialization. |
| 129 | 112 | * |
| 130 | 113 | * @link https://www.php.net/manual/en/language.oop5.magic.php#language.oop5.magic.serialize |
| 131 | 114 | * @link https://www.php.net/serialize |
| @@ -131,35 +114,18 @@ | ||
| 131 | 114 | * @link https://www.php.net/serialize |
| 132 | 115 | * |
| 133 | 116 | * @return array<array-key, T> |
| 134 | 117 | */ |
| 135 | - public function __serialize(): array | |
| 118 | + public function __serialize() : array | |
| 136 | 119 | { |
| 137 | 120 | return $this->data; |
| 138 | 121 | } |
| 139 | 122 | /** |
| 140 | - * Converts a serialized string representation into an instance object. | |
| 141 | - * | |
| 142 | - * @deprecated The Serializable interface will go away in PHP 9. | |
| 143 | - * | |
| 144 | - * @link http://php.net/manual/en/serializable.unserialize.php Serializable::unserialize() | |
| 145 | - * | |
| 146 | - * @param string $serialized A PHP serialized string to unserialize. | |
| 147 | - * | |
| 148 | - * @phpcsSuppress SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint | |
| 149 | - */ | |
| 150 | - public function unserialize($serialized): void | |
| 151 | - { | |
| 152 | - /** @var array<array-key, T> $data */ | |
| 153 | - $data = unserialize($serialized, ['allowed_classes' => \false]); | |
| 154 | - $this->data = $data; | |
| 155 | - } | |
| 156 | - /** | |
| 157 | 123 | * Adds unserialized data to the object. |
| 158 | 124 | * |
| 159 | 125 | * @param array<array-key, T> $data |
| 160 | 126 | */ |
| 161 | - public function __unserialize(array $data): void | |
| 127 | + public function __unserialize(array $data) : void | |
| 162 | 128 | { |
| 163 | 129 | $this->data = $data; |
| 164 | 130 | } |
| 165 | 131 | /** |
| @@ -166,13 +132,13 @@ | ||
| 166 | 132 | * Returns the number of items in this array. |
| 167 | 133 | * |
| 168 | 134 | * @link http://php.net/manual/en/countable.count.php Countable::count() |
| 169 | 135 | */ |
| 170 | - public function count(): int | |
| 136 | + public function count() : int | |
| 171 | 137 | { |
| 172 | 138 | return count($this->data); |
| 173 | 139 | } |
| 174 | - public function clear(): void | |
| 140 | + public function clear() : void | |
| 175 | 141 | { |
| 176 | 142 | $this->data = []; |
| 177 | 143 | } |
| 178 | 144 | /** |
| @@ -177,13 +143,13 @@ | ||
| 177 | 143 | } |
| 178 | 144 | /** |
| 179 | 145 | * @inheritDoc |
| 180 | 146 | */ |
| 181 | - public function toArray(): array | |
| 147 | + public function toArray() : array | |
| 182 | 148 | { |
| 183 | 149 | return $this->data; |
| 184 | 150 | } |
| 185 | - public function isEmpty(): bool | |
| 151 | + public function isEmpty() : bool | |
| 186 | 152 | { |
| 187 | - return count($this->data) === 0; | |
| 153 | + return $this->data === []; | |
| 188 | 154 | } |
| 189 | 155 | } |