Skip to content

Commit 8b4f09d

Browse files
committed
PHPdoc, strict types added.
1 parent 24aa8fb commit 8b4f09d

17 files changed

+106
-23
lines changed

src/Exceptions/IndexError.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace Smoren\ArrayView\Exceptions;
46

57
class IndexError extends \RuntimeException

src/Exceptions/KeyError.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace Smoren\ArrayView\Exceptions;
46

57
class KeyError extends \RuntimeException

src/Exceptions/NotSupportedError.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace Smoren\ArrayView\Exceptions;
46

57
class NotSupportedError extends \Exception

src/Exceptions/ReadonlyError.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace Smoren\ArrayView\Exceptions;
46

57
class ReadonlyError extends \RuntimeException

src/Exceptions/SizeError.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace Smoren\ArrayView\Exceptions;
46

57
class SizeError extends \RuntimeException

src/Exceptions/ValueError.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace Smoren\ArrayView\Exceptions;
46

57
class ValueError extends \RuntimeException

src/Interfaces/ArrayViewInterface.php

Lines changed: 74 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -5,80 +5,121 @@
55
namespace Smoren\ArrayView\Interfaces;
66

77
/**
8-
* @template T
8+
* Interface for a view of an array with additional methods
9+
* for filtering, mapping, and transforming the data.
10+
*
11+
* @template T The type of elements in the array
12+
*
913
* @extends \ArrayAccess<int, T|array<T>>
1014
* @extends \IteratorAggregate<int, T>
1115
*/
1216
interface ArrayViewInterface extends \ArrayAccess, \IteratorAggregate, \Countable
1317
{
1418
/**
15-
* @param array<T>|ArrayViewInterface<T> $source
16-
* @param bool|null $readonly
17-
* @return ArrayViewInterface<T>
19+
* Creates an ArrayView instance from the given source array or ArrayView.
20+
*
21+
* * If the source is not an ArrayView, a new ArrayView is created with the provided source.
22+
* * If the source is an ArrayView and the `readonly` parameter is specified as `true`,
23+
* a new readonly ArrayView is created.
24+
* * If the source is an ArrayView and it is already readonly, the same ArrayView is returned.
25+
*
26+
* @param array<T>|ArrayViewInterface<T> $source The source array or ArrayView to create a view from.
27+
* @param bool|null $readonly Optional flag to indicate whether the view should be readonly.
28+
*
29+
* @return ArrayViewInterface<T> An ArrayView instance based on the source array or ArrayView.
1830
*/
1931
public static function toView(&$source, ?bool $readonly = null): ArrayViewInterface;
2032

2133
/**
22-
* @param array<T>|ArrayViewInterface<T> $source
23-
* @param bool|null $readonly
24-
* @return ArrayViewInterface<T>
34+
* Creates an unlinked from source ArrayView instance from the given source array or ArrayView.
35+
*
36+
* * If the source is not an ArrayView, a new ArrayView is created with the provided source.
37+
* * If the source is an ArrayView and the `readonly` parameter is specified as `true`,
38+
* a new readonly ArrayView is created.
39+
* * If the source is an ArrayView and it is already readonly, the same ArrayView is returned.
40+
*
41+
* @param array<T>|ArrayViewInterface<T> $source The source array or ArrayView to create a view from.
42+
* @param bool|null $readonly Optional flag to indicate whether the view should be readonly.
43+
*
44+
* @return ArrayViewInterface<T> An ArrayView instance based on the source array or ArrayView.
2545
*/
2646
public static function toUnlinkedView($source, ?bool $readonly = null): ArrayViewInterface;
2747

2848
/**
29-
* @return array<T>
49+
* Returns the array representation of the view.
50+
*
51+
* @return array<T> The array representation of the view.
3052
*/
3153
public function toArray(): array;
3254

3355
/**
34-
* @param callable(T): bool $predicate
35-
* @return ArrayViewInterface<T>
56+
* Filters the elements in the view based on a predicate function.
57+
*
58+
* @param callable(T): bool $predicate Function that returns a boolean value for each element.
59+
*
60+
* @return ArrayViewInterface<T> A new view with elements that satisfy the predicate.
3661
*/
3762
public function filter(callable $predicate): ArrayViewInterface;
3863

3964
/**
40-
* @param callable(T): bool $predicate
41-
* @return MaskSelectorInterface
65+
* Checks if all elements in the view satisfy a given predicate function.
66+
*
67+
* @param callable(T): bool $predicate Function that returns a boolean value for each element.
68+
*
69+
* @return MaskSelectorInterface Boolean mask for selecting elements that satisfy the predicate.
4270
*/
4371
public function is(callable $predicate): MaskSelectorInterface;
4472

4573
/**
46-
* @param ArraySelectorInterface|string $selector
47-
* @param bool|null $readonly
48-
* @return ArrayViewInterface<T>
74+
* Returns a subview of this view based on a selector or string slice.
75+
*
76+
* @param ArraySelectorInterface|string $selector The selector or string to filter the subview.
77+
* @param bool|null $readonly Flag indicating if the subview should be read-only.
78+
*
79+
* @return ArrayViewInterface<T> A new view representing the subview of this view.
4980
*/
5081
public function subview($selector, bool $readonly = null): ArrayViewInterface;
5182

5283
/**
53-
* @param callable(T, int): T $mapper
84+
* Applies a transformation function to each element in the view.
85+
*
86+
* @param callable(T, int): T $mapper Function to transform each element.
5487
*
55-
* @return ArrayViewInterface<T>
88+
* @return ArrayViewInterface<T> this view.
5689
*/
5790
public function apply(callable $mapper): self;
5891

5992
/**
60-
* @template U
93+
* Applies a transformation function using another array or view as rhs values for a binary operation.
94+
*
95+
* @template U The type rhs of a binary operation.
6196
*
62-
* @param array<U>|ArrayViewInterface<U> $data
63-
* @param callable(T, U, int): T $mapper
97+
* @param array<U>|ArrayViewInterface<U> $data The rhs values for a binary operation.
98+
* @param callable(T, U, int): T $mapper Function to transform each pair of elements.
6499
*
65-
* @return ArrayViewInterface<T>
100+
* @return ArrayViewInterface<T> this view.
66101
*/
67102
public function applyWith($data, callable $mapper): self;
68103

69104
/**
70-
* @param array<T>|ArrayViewInterface<T>|T $newValues
105+
* Sets new values for the elements in the view.
71106
*
72-
* @return ArrayViewInterface<T>
107+
* @param array<T>|ArrayViewInterface<T>|T $newValues The new values to set.
108+
*
109+
* @return ArrayViewInterface<T> this view.
73110
*/
74111
public function set($newValues): self;
75112

76113
/**
114+
* Return true if view is readonly, otherwise false.
115+
*
77116
* @return bool
78117
*/
79118
public function isReadonly(): bool;
80119

81120
/**
121+
* Return size of the view.
122+
*
82123
* @return int
83124
*/
84125
public function count(): int;
@@ -87,13 +128,17 @@ public function count(): int;
87128
* @param numeric|string|ArraySelectorInterface $offset
88129
*
89130
* @return bool
131+
*
132+
* {@inheritDoc}
90133
*/
91134
public function offsetExists($offset): bool;
92135

93136
/**
94137
* @param numeric|string|ArraySelectorInterface $offset
95138
*
96139
* @return T|array<T>
140+
*
141+
* {@inheritDoc}
97142
*/
98143
#[\ReturnTypeWillChange]
99144
public function offsetGet($offset);
@@ -103,17 +148,23 @@ public function offsetGet($offset);
103148
* @param T|array<T>|ArrayViewInterface<T> $value
104149
*
105150
* @return void
151+
*
152+
* {@inheritDoc}
106153
*/
107154
public function offsetSet($offset, $value): void;
108155

109156
/**
110157
* @param numeric|string|ArraySelectorInterface $offset
111158
*
112159
* @return void
160+
*
161+
* {@inheritDoc}
113162
*/
114163
public function offsetUnset($offset): void;
115164

116165
/**
166+
* Return iterator to iterate the view elements.
167+
*
117168
* @return \Generator<int, T>
118169
*/
119170
public function getIterator(): \Generator;

src/Selectors/IndexListSelector.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace Smoren\ArrayView\Selectors;
46

57
use Smoren\ArrayView\Interfaces\ArrayViewInterface;

src/Selectors/MaskSelector.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace Smoren\ArrayView\Selectors;
46

57
use Smoren\ArrayView\Interfaces\ArrayViewInterface;

src/Selectors/SliceSelector.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace Smoren\ArrayView\Selectors;
46

57
use Smoren\ArrayView\Interfaces\ArraySelectorInterface;

0 commit comments

Comments
 (0)