Skip to content

Commit 7aa4668

Browse files
committed
PHPdoc added
1 parent f332964 commit 7aa4668

22 files changed

+362
-94
lines changed

src/Exceptions/IndexError.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44

55
namespace Smoren\ArrayView\Exceptions;
66

7+
/**
8+
* Error class for index-related errors.
9+
*/
710
class IndexError extends \RuntimeException
811
{
912
}

src/Exceptions/KeyError.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44

55
namespace Smoren\ArrayView\Exceptions;
66

7+
/**
8+
* Error class for key-related errors.
9+
*/
710
class KeyError extends \RuntimeException
811
{
912
}

src/Exceptions/NotSupportedError.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44

55
namespace Smoren\ArrayView\Exceptions;
66

7+
/**
8+
* Error class for not supported errors.
9+
*/
710
class NotSupportedError extends \Exception
811
{
912
}

src/Exceptions/ReadonlyError.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44

55
namespace Smoren\ArrayView\Exceptions;
66

7+
/**
8+
* Error class for readonly-related errors.
9+
*/
710
class ReadonlyError extends \RuntimeException
811
{
912
}

src/Exceptions/SizeError.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44

55
namespace Smoren\ArrayView\Exceptions;
66

7+
/**
8+
* Error class for size-related errors.
9+
*/
710
class SizeError extends \RuntimeException
811
{
912
}

src/Exceptions/ValueError.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44

55
namespace Smoren\ArrayView\Exceptions;
66

7+
/**
8+
* Error class for value-related errors.
9+
*/
710
class ValueError extends \RuntimeException
811
{
912
}

src/Interfaces/ArraySelectorInterface.php

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,26 @@
44

55
namespace Smoren\ArrayView\Interfaces;
66

7+
/**
8+
* Interface for selecting elements from an array view.
9+
*/
710
interface ArraySelectorInterface
811
{
912
/**
10-
* @template T
13+
* Selects elements from a source array view based on the selector criteria.
1114
*
12-
* @param ArrayViewInterface<T> $source
13-
* @param bool|null $readonly
15+
* @template T The type of elements in the source array view.
1416
*
15-
* @return ArrayViewInterface<T>
17+
* @param ArrayViewInterface<T> $source The source array view to select elements from.
18+
* @param bool|null $readonly Flag indicating if the result view should be read-only.
19+
*
20+
* @return ArrayViewInterface<T> A new view with selected elements from the source.
1621
*/
1722
public function select(ArrayViewInterface $source, ?bool $readonly = null): ArrayViewInterface;
1823

1924
/**
25+
* Return value of the selector.
26+
*
2027
* @return mixed
2128
*/
2229
public function getValue();

src/Interfaces/ArrayViewInterface.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@
44

55
namespace Smoren\ArrayView\Interfaces;
66

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+
714
/**
815
* Interface for a view of an array with additional methods
916
* for filtering, mapping, and transforming the data.
@@ -27,6 +34,9 @@ interface ArrayViewInterface extends \ArrayAccess, \IteratorAggregate, \Countabl
2734
* @param bool|null $readonly Optional flag to indicate whether the view should be readonly.
2835
*
2936
* @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.
3040
*/
3141
public static function toView(&$source, ?bool $readonly = null): ArrayViewInterface;
3242

@@ -42,6 +52,9 @@ public static function toView(&$source, ?bool $readonly = null): ArrayViewInterf
4252
* @param bool|null $readonly Optional flag to indicate whether the view should be readonly.
4353
*
4454
* @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.
4558
*/
4659
public static function toUnlinkedView($source, ?bool $readonly = null): ArrayViewInterface;
4760

@@ -98,6 +111,9 @@ public function apply(callable $mapper): self;
98111
* @param callable(T, U, int): T $mapper Function to transform each pair of elements.
99112
*
100113
* @return ArrayViewInterface<T> this view.
114+
*
115+
* @throws ValueError if the $data is not sequential array.
116+
* @throws SizeError if size of $data not equals to size of the view.
101117
*/
102118
public function applyWith($data, callable $mapper): self;
103119

@@ -107,6 +123,9 @@ public function applyWith($data, callable $mapper): self;
107123
* @param array<T>|ArrayViewInterface<T>|T $newValues The new values to set.
108124
*
109125
* @return ArrayViewInterface<T> this view.
126+
*
127+
* @throws ValueError if the $newValues is not sequential array.
128+
* @throws SizeError if size of $newValues not equals to size of the view.
110129
*/
111130
public function set($newValues): self;
112131

@@ -138,6 +157,9 @@ public function offsetExists($offset): bool;
138157
*
139158
* @return T|array<T>
140159
*
160+
* @throws IndexError if the offset is out of range.
161+
* @throws KeyError if the key is invalid.
162+
*
141163
* {@inheritDoc}
142164
*/
143165
#[\ReturnTypeWillChange]
@@ -149,6 +171,10 @@ public function offsetGet($offset);
149171
*
150172
* @return void
151173
*
174+
* @throws IndexError if the offset is out of range.
175+
* @throws KeyError if the key is invalid.
176+
* @throws ReadonlyError if the object is readonly.
177+
*
152178
* {@inheritDoc}
153179
*/
154180
public function offsetSet($offset, $value): void;
@@ -158,6 +184,8 @@ public function offsetSet($offset, $value): void;
158184
*
159185
* @return void
160186
*
187+
* @throws NotSupportedError always.
188+
*
161189
* {@inheritDoc}
162190
*/
163191
public function offsetUnset($offset): void;

src/Interfaces/IndexListSelectorInterface.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,14 @@
44

55
namespace Smoren\ArrayView\Interfaces;
66

7+
/**
8+
* Interface for selecting elements from an array view by boolean mask.
9+
*/
710
interface IndexListSelectorInterface extends ArraySelectorInterface
811
{
912
/**
13+
* Return index list array.
14+
*
1015
* @return array<int>
1116
*/
1217
public function getValue(): array;

src/Interfaces/MaskSelectorInterface.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,14 @@
44

55
namespace Smoren\ArrayView\Interfaces;
66

7+
/**
8+
* Interface for selecting elements from an array view by boolean mask.
9+
*/
710
interface MaskSelectorInterface extends ArraySelectorInterface
811
{
912
/**
13+
* Return boolean mask array.
14+
*
1015
* @return array<bool>
1116
*/
1217
public function getValue(): array;

0 commit comments

Comments
 (0)