Smoren /
array-view-php
| 1 | <?php |
||
| 2 | |||
| 3 | declare(strict_types=1); |
||
| 4 | |||
| 5 | namespace Smoren\ArrayView\Interfaces; |
||
| 6 | |||
| 7 | use Smoren\ArrayView\Exceptions\IndexError; |
||
| 8 | use Smoren\ArrayView\Exceptions\KeyError; |
||
| 9 | use Smoren\ArrayView\Exceptions\NotSupportedError; |
||
| 10 | use Smoren\ArrayView\Exceptions\ReadonlyError; |
||
| 11 | use Smoren\ArrayView\Exceptions\SizeError; |
||
| 12 | use Smoren\ArrayView\Exceptions\ValueError; |
||
| 13 | |||
| 14 | /** |
||
| 15 | * Interface for a view of an array with additional methods |
||
| 16 | * for filtering, mapping, and transforming the data. |
||
| 17 | * |
||
| 18 | * @template T The type of elements in the array |
||
| 19 | * |
||
| 20 | * @extends \ArrayAccess<int|string|array<int|bool>|ArrayViewInterface<int|bool>|ArraySelectorInterface, T|array<T>> |
||
| 21 | * @extends \IteratorAggregate<int, T> |
||
| 22 | */ |
||
| 23 | interface ArrayViewInterface extends \ArrayAccess, \IteratorAggregate, \Countable |
||
| 24 | { |
||
| 25 | /** |
||
| 26 | * Creates an ArrayView instance from the given source array or ArrayView. |
||
| 27 | * |
||
| 28 | * * If the source is not an ArrayView, a new ArrayView is created with the provided source. |
||
| 29 | * * If the source is an ArrayView and the `readonly` parameter is specified as `true`, |
||
| 30 | * a new readonly ArrayView is created. |
||
| 31 | * * If the source is an ArrayView and it is already readonly, the same ArrayView is returned. |
||
| 32 | * |
||
| 33 | * @param array<T>|ArrayViewInterface<T> $source The source array or ArrayView to create a view from. |
||
| 34 | * @param bool|null $readonly Optional flag to indicate whether the view should be readonly. |
||
| 35 | * |
||
| 36 | * @return ArrayViewInterface<T> An ArrayView instance based on the source array or ArrayView. |
||
| 37 | * |
||
| 38 | * @throws ValueError if the array is not sequential. |
||
| 39 | * @throws ReadonlyError if the source is readonly and trying to create a non-readonly view. |
||
| 40 | */ |
||
| 41 | public static function toView(&$source, ?bool $readonly = null): ArrayViewInterface; |
||
| 42 | |||
| 43 | /** |
||
| 44 | * Creates an unlinked from source ArrayView instance from the given source array or ArrayView. |
||
| 45 | * |
||
| 46 | * * If the source is not an ArrayView, a new ArrayView is created with the provided source. |
||
| 47 | * * If the source is an ArrayView and the `readonly` parameter is specified as `true`, |
||
| 48 | * a new readonly ArrayView is created. |
||
| 49 | * * If the source is an ArrayView and it is already readonly, the same ArrayView is returned. |
||
| 50 | * |
||
| 51 | * @param array<T>|ArrayViewInterface<T> $source The source array or ArrayView to create a view from. |
||
| 52 | * @param bool|null $readonly Optional flag to indicate whether the view should be readonly. |
||
| 53 | * |
||
| 54 | * @return ArrayViewInterface<T> An ArrayView instance based on the source array or ArrayView. |
||
| 55 | * |
||
| 56 | * @throws ValueError if the array is not sequential. |
||
| 57 | * @throws ReadonlyError if the source is readonly and trying to create a non-readonly view. |
||
| 58 | */ |
||
| 59 | public static function toUnlinkedView($source, ?bool $readonly = null): ArrayViewInterface; |
||
| 60 | |||
| 61 | /** |
||
| 62 | * Returns the array representation of the view. |
||
| 63 | * |
||
| 64 | * @return array<T> The array representation of the view. |
||
| 65 | */ |
||
| 66 | public function toArray(): array; |
||
| 67 | |||
| 68 | /** |
||
| 69 | * Returns a subview of this view based on a selector or string slice. |
||
| 70 | * |
||
| 71 | * @param string|array<int|bool>|ArrayViewInterface<int|bool>|ArraySelectorInterface $selector The selector or |
||
| 72 | * string to filter the subview. |
||
| 73 | * @param bool|null $readonly Flag indicating if the subview should be read-only. |
||
| 74 | * |
||
| 75 | * @return ArrayViewInterface<T> A new view representing the subview of this view. |
||
| 76 | * |
||
| 77 | * @throws IndexError if the selector is IndexListSelector and some indexes are out of range. |
||
| 78 | * @throws SizeError if the selector is MaskSelector and size of the mask not equals to size of the view. |
||
| 79 | */ |
||
| 80 | public function subview($selector, bool $readonly = null): ArrayViewInterface; |
||
| 81 | |||
| 82 | /** |
||
| 83 | * Filters the elements in the view based on a predicate function. |
||
| 84 | * |
||
| 85 | * @param callable(T, int): bool $predicate Function that returns a boolean value for each element. |
||
| 86 | * |
||
| 87 | * @return ArrayViewInterface<T> A new view with elements that satisfy the predicate. |
||
| 88 | */ |
||
| 89 | public function filter(callable $predicate): ArrayViewInterface; |
||
| 90 | |||
| 91 | /** |
||
| 92 | * Checks if all elements in the view satisfy a given predicate function. |
||
| 93 | * |
||
| 94 | * @param callable(T, int): bool $predicate Function that returns a boolean value for each element. |
||
| 95 | * |
||
| 96 | * @return MaskSelectorInterface Boolean mask for selecting elements that satisfy the predicate. |
||
| 97 | * |
||
| 98 | * @see ArrayViewInterface::match() Full synonim. |
||
| 99 | */ |
||
| 100 | public function is(callable $predicate): MaskSelectorInterface; |
||
| 101 | |||
| 102 | /** |
||
| 103 | * Checks if all elements in the view satisfy a given predicate function. |
||
| 104 | * |
||
| 105 | * @param callable(T, int): bool $predicate Function that returns a boolean value for each element. |
||
| 106 | * |
||
| 107 | * @return MaskSelectorInterface Boolean mask for selecting elements that satisfy the predicate. |
||
| 108 | * |
||
| 109 | * @see ArrayViewInterface::is() Full synonim. |
||
| 110 | */ |
||
| 111 | public function match(callable $predicate): MaskSelectorInterface; |
||
| 112 | |||
| 113 | /** |
||
| 114 | * Compares the elements of the current ArrayView instance with another array or ArrayView |
||
| 115 | * using the provided comparator function. |
||
| 116 | * |
||
| 117 | * @template U The type of the elements in the array for comparison with. |
||
| 118 | * |
||
| 119 | * @param array<U>|ArrayViewInterface<U>|U $data The array or ArrayView to compare to. |
||
| 120 | * @param callable(T, U, int): bool $comparator Function that determines the comparison logic between the elements. |
||
| 121 | * |
||
| 122 | * @return MaskSelectorInterface A MaskSelector instance representing the results of the element comparisons. |
||
| 123 | * |
||
| 124 | * @throws ValueError if the $data is not sequential array. |
||
| 125 | * @throws SizeError if size of $data not equals to size of the view. |
||
| 126 | */ |
||
| 127 | public function matchWith($data, callable $comparator): MaskSelectorInterface; |
||
| 128 | |||
| 129 | /** |
||
| 130 | * Transforms each element of the array using the given callback function. |
||
| 131 | * |
||
| 132 | * The callback function receives two parameters: the current element of the array and its index. |
||
| 133 | * |
||
| 134 | * @param callable(T, int): T $mapper Function to transform each element. |
||
| 135 | * |
||
| 136 | * @return array<T> New array with transformed elements of this view. |
||
| 137 | */ |
||
| 138 | public function map(callable $mapper): array; |
||
| 139 | |||
| 140 | /** |
||
| 141 | * Transforms each pair of elements from the current array view and the provided data array using the given |
||
| 142 | * callback function. |
||
| 143 | * |
||
| 144 | * The callback function receives three parameters: the current element of the current array view, |
||
| 145 | * the corresponding element of the data array, and the index. |
||
| 146 | * |
||
| 147 | * @template U The type rhs of a binary operation. |
||
| 148 | * |
||
| 149 | * @param array<U>|ArrayViewInterface<U>|U $data The rhs values for a binary operation. |
||
| 150 | * @param callable(T, U, int): T $mapper Function to transform each pair of elements. |
||
| 151 | * |
||
| 152 | * @return array<mixed> New array with transformed elements of this view. |
||
| 153 | * |
||
| 154 | * @throws ValueError if the $data is not sequential array. |
||
| 155 | * @throws SizeError if size of $data not equals to size of the view. |
||
| 156 | */ |
||
| 157 | public function mapWith($data, callable $mapper): array; |
||
| 158 | |||
| 159 | /** |
||
| 160 | * Applies a transformation function to each element in the view. |
||
| 161 | * |
||
| 162 | * @param callable(T, int): T $mapper Function to transform each element. |
||
| 163 | * |
||
| 164 | * @return ArrayViewInterface<T> this view. |
||
| 165 | */ |
||
| 166 | public function apply(callable $mapper): self; |
||
| 167 | |||
| 168 | /** |
||
| 169 | * Applies a transformation function using another array or view as rhs values for a binary operation. |
||
| 170 | * |
||
| 171 | * @template U The type rhs of a binary operation. |
||
| 172 | * |
||
| 173 | * @param array<U>|ArrayViewInterface<U> $data The rhs values for a binary operation. |
||
| 174 | * @param callable(T, U, int): T $mapper Function to transform each pair of elements. |
||
| 175 | * |
||
| 176 | * @return ArrayViewInterface<T> this view. |
||
| 177 | * |
||
| 178 | * @throws ValueError if the $data is not sequential array. |
||
| 179 | * @throws SizeError if size of $data not equals to size of the view. |
||
| 180 | */ |
||
| 181 | public function applyWith($data, callable $mapper): self; |
||
| 182 | |||
| 183 | /** |
||
| 184 | * Sets new values for the elements in the view. |
||
| 185 | * |
||
| 186 | * @param array<T>|ArrayViewInterface<T>|T $newValues The new values to set. |
||
| 187 | * |
||
| 188 | * @return ArrayViewInterface<T> this view. |
||
| 189 | * |
||
| 190 | * @throws ValueError if the $newValues is not sequential array. |
||
| 191 | * @throws SizeError if size of $newValues not equals to size of the view. |
||
| 192 | */ |
||
| 193 | public function set($newValues): self; |
||
| 194 | |||
| 195 | /** |
||
| 196 | * Return true if view is readonly, otherwise false. |
||
| 197 | * |
||
| 198 | * @return bool |
||
| 199 | */ |
||
| 200 | public function isReadonly(): bool; |
||
| 201 | |||
| 202 | /** |
||
| 203 | * Return size of the view. |
||
| 204 | * |
||
| 205 | * @return int |
||
| 206 | */ |
||
| 207 | public function count(): int; |
||
| 208 | |||
| 209 | /** |
||
| 210 | * @param numeric|string|ArraySelectorInterface $offset |
||
|
0 ignored issues
–
show
|
|||
| 211 | * |
||
| 212 | * @return bool |
||
| 213 | * |
||
| 214 | * {@inheritDoc} |
||
| 215 | */ |
||
| 216 | public function offsetExists($offset): bool; |
||
| 217 | |||
| 218 | /** |
||
| 219 | * @param numeric|string|ArraySelectorInterface $offset |
||
| 220 | * |
||
| 221 | * @return T|array<T> |
||
| 222 | * |
||
| 223 | * @throws IndexError if the offset is out of range. |
||
| 224 | * @throws KeyError if the key is invalid. |
||
| 225 | * |
||
| 226 | * {@inheritDoc} |
||
| 227 | */ |
||
| 228 | #[\ReturnTypeWillChange] |
||
| 229 | public function offsetGet($offset); |
||
| 230 | |||
| 231 | /** |
||
| 232 | * @param numeric|string|ArraySelectorInterface $offset |
||
| 233 | * @param T|array<T>|ArrayViewInterface<T> $value |
||
|
0 ignored issues
–
show
The type
Smoren\ArrayView\Interfaces\T was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths Loading history...
|
|||
| 234 | * |
||
| 235 | * @return void |
||
| 236 | * |
||
| 237 | * @throws IndexError if the offset is out of range. |
||
| 238 | * @throws KeyError if the key is invalid. |
||
| 239 | * @throws ReadonlyError if the object is readonly. |
||
| 240 | * |
||
| 241 | * {@inheritDoc} |
||
| 242 | */ |
||
| 243 | public function offsetSet($offset, $value): void; |
||
| 244 | |||
| 245 | /** |
||
| 246 | * @param numeric|string|ArraySelectorInterface $offset |
||
| 247 | * |
||
| 248 | * @return void |
||
| 249 | * |
||
| 250 | * @throws NotSupportedError always. |
||
| 251 | * |
||
| 252 | * {@inheritDoc} |
||
| 253 | */ |
||
| 254 | public function offsetUnset($offset): void; |
||
| 255 | |||
| 256 | /** |
||
| 257 | * Return iterator to iterate the view elements. |
||
| 258 | * |
||
| 259 | * @return \Generator<int, T> |
||
| 260 | */ |
||
| 261 | public function getIterator(): \Generator; |
||
| 262 | } |
||
| 263 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths