@@ -14,19 +14,18 @@ class OutputCollectionMutator extends AbstractCollectionMutator
1414 public function __construct (array $ outputs )
1515 {
1616 /** @var OutputMutator[] $set */
17- $ this -> set = new \ SplFixedArray ( count ( $ outputs )) ;
17+ $ set = [] ;
1818 foreach ($ outputs as $ i => $ output ) {
1919 /** @var int $i */
20- $ this -> set [$ i ] = new OutputMutator ($ output );
20+ $ set [$ i ] = new OutputMutator ($ output );
2121 }
22+
23+ $ this ->set = $ set ;
2224 }
2325
24- /**
25- * @return OutputMutator
26- */
2726 public function current (): OutputMutator
2827 {
29- return $ this -> set -> current ();
28+ return parent :: current ();
3029 }
3130
3231 /**
@@ -35,11 +34,7 @@ public function current(): OutputMutator
3534 */
3635 public function offsetGet ($ offset ): OutputMutator
3736 {
38- if (!$ this ->set ->offsetExists ($ offset )) {
39- throw new \OutOfRangeException ('Nothing found at this offset ' );
40- }
41-
42- return $ this ->set ->offsetGet ($ offset );
37+ return parent ::offsetGet ($ offset );
4338 }
4439
4540 /**
@@ -56,25 +51,22 @@ public function done(): array
5651 }
5752
5853 /**
59- * @param int $start
60- * @param int $length
61- * @return $this
54+ * Return an array containing values beginning at index $start and ending
55+ * with index $start + $length. An exception is thrown if start or $length
56+ * is out of bounds
6257 */
63- public function slice (int $ start , int $ length )
58+ public function slice (int $ start , int $ length ): OutputCollectionMutator
6459 {
6560 $ end = count ($ this ->set );
6661 if ($ start > $ end || $ length > $ end ) {
6762 throw new \RuntimeException ('Invalid start or length ' );
6863 }
6964
70- $ this ->set = \SplFixedArray:: fromArray ( array_slice ($ this ->set -> toArray () , $ start , $ length), false );
65+ $ this ->set = array_slice ($ this ->set , $ start , $ length );
7166 return $ this ;
7267 }
7368
74- /**
75- * @return $this
76- */
77- public function null ()
69+ public function null (): OutputCollectionMutator
7870 {
7971 $ this ->slice (0 , 0 );
8072 return $ this ;
@@ -84,11 +76,9 @@ public function null()
8476 * @param TransactionOutputInterface $output
8577 * @return $this
8678 */
87- public function add (TransactionOutputInterface $ output )
79+ public function add (TransactionOutputInterface $ output ): OutputCollectionMutator
8880 {
89- $ size = $ this ->set ->getSize ();
90- $ this ->set ->setSize ($ size + 1 );
91-
81+ $ size = $ this ->count ();
9282 $ this ->set [$ size ] = new OutputMutator ($ output );
9383 return $ this ;
9484 }
@@ -98,8 +88,11 @@ public function add(TransactionOutputInterface $output)
9888 * @param TransactionOutputInterface $output
9989 * @return $this
10090 */
101- public function set ($ i , TransactionOutputInterface $ output )
91+ public function set (int $ i , TransactionOutputInterface $ output ): OutputCollectionMutator
10292 {
93+ if ($ i > count ($ this ->set )) {
94+ throw new \InvalidArgumentException ();
95+ }
10396 $ this ->set [$ i ] = new OutputMutator ($ output );
10497 return $ this ;
10598 }
0 commit comments