44
55namespace Brick \Std ;
66
7+ use ArrayAccess ;
8+ use Countable ;
9+ use InvalidArgumentException ;
10+ use IteratorAggregate ;
11+ use SplFixedArray ;
12+ use Traversable ;
13+
714/**
815 * An array of fixed length.
916 *
1017 * This class internally wraps SplFixedArray.
1118 */
12- final class FixedArray implements \ Countable, \ IteratorAggregate, \ ArrayAccess
19+ final class FixedArray implements Countable, IteratorAggregate, ArrayAccess
1320{
14- private \ SplFixedArray $ splFixedArray ;
21+ private SplFixedArray $ splFixedArray ;
1522
1623 /**
1724 * Class constructor.
18- *
19- * @param \SplFixedArray $fixedArray
2025 */
21- public function __construct (\ SplFixedArray $ fixedArray )
26+ public function __construct (SplFixedArray $ fixedArray )
2227 {
2328 $ this ->splFixedArray = $ fixedArray ;
2429 }
2530
26- /**
27- * @param int $size
28- *
29- * @return FixedArray
30- */
31- public static function create (int $ size = 0 ) : FixedArray
31+ public static function create (int $ size = 0 ): FixedArray
3232 {
33- return new FixedArray (new \ SplFixedArray ($ size ));
33+ return new FixedArray (new SplFixedArray ($ size ));
3434 }
3535
3636 /**
3737 * Creates a FixedArray from a PHP array.
3838 *
39- * @param array $array
40- * @param bool $saveIndexes
41- *
42- * @return FixedArray
43- *
44- * @throws \InvalidArgumentException If the array contains non-numeric or negative indexes.
39+ * @throws InvalidArgumentException If the array contains non-numeric or negative indexes.
4540 */
46- public static function fromArray (array $ array , bool $ saveIndexes = true ) : FixedArray
41+ public static function fromArray (array $ array , bool $ saveIndexes = true ): FixedArray
4742 {
48- return new FixedArray (\ SplFixedArray::fromArray ($ array , $ saveIndexes ));
43+ return new FixedArray (SplFixedArray::fromArray ($ array , $ saveIndexes ));
4944 }
5045
51- /**
52- * @return array
53- */
54- public function toArray () : array
46+ public function toArray (): array
5547 {
5648 return $ this ->splFixedArray ->toArray ();
5749 }
5850
5951 /**
6052 * Returns the size of the array.
61- *
62- * @return int
6353 */
64- public function getSize () : int
54+ public function getSize (): int
6555 {
6656 return $ this ->splFixedArray ->getSize ();
6757 }
6858
69- /**
70- * @param int $size
71- *
72- * @return void
73- */
74- public function setSize (int $ size ) : void
59+ public function setSize (int $ size ): void
7560 {
7661 $ this ->splFixedArray ->setSize ($ size );
7762 }
@@ -80,10 +65,8 @@ public function setSize(int $size) : void
8065 * Returns the size of the array.
8166 *
8267 * This is an alias of getSize(), required by interface Countable.
83- *
84- * @return int
8568 */
86- public function count () : int
69+ public function count (): int
8770 {
8871 return $ this ->splFixedArray ->count ();
8972 }
@@ -94,10 +77,8 @@ public function count() : int
9477 * Required by interface ArrayAccess.
9578 *
9679 * @param int $offset
97- *
98- * @return bool
9980 */
100- public function offsetExists (mixed $ offset ) : bool
81+ public function offsetExists (mixed $ offset ): bool
10182 {
10283 return $ this ->splFixedArray ->offsetExists ($ offset );
10384 }
@@ -108,8 +89,6 @@ public function offsetExists(mixed $offset) : bool
10889 * Required by interface ArrayAccess.
10990 *
11091 * @param int $offset
111- *
112- * @return mixed
11392 */
11493 public function offsetGet (mixed $ offset ): mixed
11594 {
@@ -121,12 +100,9 @@ public function offsetGet(mixed $offset): mixed
121100 *
122101 * Required by interface ArrayAccess.
123102 *
124- * @param int $offset
125- * @param mixed $value
126- *
127- * @return void
103+ * @param int $offset
128104 */
129- public function offsetSet (mixed $ offset , mixed $ value ) : void
105+ public function offsetSet (mixed $ offset , mixed $ value ): void
130106 {
131107 $ this ->splFixedArray ->offsetSet ($ offset , $ value );
132108 }
@@ -137,10 +113,8 @@ public function offsetSet(mixed $offset, mixed $value) : void
137113 * Required by interface ArrayAccess.
138114 *
139115 * @param int $offset
140- *
141- * @return void
142116 */
143- public function offsetUnset (mixed $ offset ) : void
117+ public function offsetUnset (mixed $ offset ): void
144118 {
145119 $ this ->splFixedArray ->offsetUnset ($ offset );
146120 }
@@ -149,10 +123,8 @@ public function offsetUnset(mixed $offset) : void
149123 * Returns an iterator for this fixed array.
150124 *
151125 * Required by interface IteratorAggregate.
152- *
153- * @return \Traversable
154126 */
155- public function getIterator () : \ Traversable
127+ public function getIterator (): Traversable
156128 {
157129 return $ this ->splFixedArray ;
158130 }
@@ -162,10 +134,8 @@ public function getIterator() : \Traversable
162134 *
163135 * @param int $index1 The index of the first entry.
164136 * @param int $index2 The index of the second entry.
165- *
166- * @return void
167137 */
168- public function swap (int $ index1 , int $ index2 ) : void
138+ public function swap (int $ index1 , int $ index2 ): void
169139 {
170140 if ($ index1 !== $ index2 ) {
171141 $ value = $ this [$ index1 ];
@@ -179,12 +149,8 @@ public function swap(int $index1, int $index2) : void
179149 *
180150 * This will effectively swap this entry with the next entry.
181151 * If this entry is the last one in the array, this method will do nothing.
182- *
183- * @param int $index
184- *
185- * @return void
186152 */
187- public function shiftUp (int $ index ) : void
153+ public function shiftUp (int $ index ): void
188154 {
189155 if ($ index + 1 === $ this ->count ()) {
190156 return ;
@@ -198,12 +164,8 @@ public function shiftUp(int $index) : void
198164 *
199165 * This will effectively swap this entry with the previous entry.
200166 * If the entry is the first one in the array, this method will do nothing.
201- *
202- * @param int $index
203- *
204- * @return void
205167 */
206- public function shiftDown (int $ index ) : void
168+ public function shiftDown (int $ index ): void
207169 {
208170 if ($ index === 0 ) {
209171 return ;
@@ -217,10 +179,8 @@ public function shiftDown(int $index) : void
217179 *
218180 * @param int $index The index of the entry.
219181 * @param int $newIndex The index to shift the entry to.
220- *
221- * @return void
222182 */
223- public function shiftTo (int $ index , int $ newIndex ) : void
183+ public function shiftTo (int $ index , int $ newIndex ): void
224184 {
225185 while ($ index > $ newIndex ) {
226186 $ this ->shiftDown ($ index );
0 commit comments