@@ -28,25 +28,27 @@ class Slice
2828
2929 /**
3030 * @param string|Slice $s
31- * @return void
31+ *
32+ * @return Slice
3233 */
3334 public static function toSlice ($ s ): Slice
3435 {
3536 if ($ s instanceof Slice) {
3637 return $ s ;
3738 }
3839
39- if (!static ::isSliceString ($ s )) {
40+ if (!self ::isSliceString ($ s )) {
4041 throw new ValueError ("Invalid slice: \"{$ s }\". " );
4142 }
4243
43- $ slice = static ::parseSliceString ($ s );
44+ $ slice = self ::parseSliceString ($ s );
4445
4546 return new Slice (...$ slice );
4647 }
4748
4849 /**
4950 * @param mixed $s
51+ *
5052 * @return bool
5153 */
5254 public static function isSlice ($ s ): bool
@@ -56,6 +58,7 @@ public static function isSlice($s): bool
5658
5759 /**
5860 * @param mixed $s
61+ *
5962 * @return bool
6063 */
6164 public static function isSliceString ($ s ): bool
@@ -72,7 +75,7 @@ public static function isSliceString($s): bool
7275 return false ;
7376 }
7477
75- $ slice = static ::parseSliceString ($ s );
78+ $ slice = self ::parseSliceString ($ s );
7679
7780 return !(\count ($ slice ) < 1 || \count ($ slice ) > 3 );
7881 }
@@ -89,6 +92,11 @@ public function __construct(?int $start = null, ?int $end = null, ?int $step = n
8992 $ this ->step = $ step ;
9093 }
9194
95+ /**
96+ * @param int $containerLength
97+ *
98+ * @return NormalizedSlice
99+ */
92100 public function normalize (int $ containerLength ): NormalizedSlice
93101 {
94102 // TODO: Need refactor
@@ -103,9 +111,9 @@ public function normalize(int $containerLength): NormalizedSlice
103111 $ start = $ this ->start ?? ($ step > 0 ? 0 : $ containerLength - 1 );
104112 $ end = $ this ->end ?? ($ step > 0 ? $ containerLength : -1 );
105113
106- $ start = round ($ start );
107- $ end = round ($ end );
108- $ step = round ($ step );
114+ $ start = intval ( round ($ start) );
115+ $ end = intval ( round ($ end) );
116+ $ step = intval ( round ($ step) );
109117
110118 $ start = Util::normalizeIndex ($ start , $ containerLength , false );
111119 $ end = Util::normalizeIndex ($ end , $ containerLength , false );
@@ -138,7 +146,7 @@ public function toString(): string
138146
139147 /**
140148 * @param string $s
141- * @return array<int>
149+ * @return array<int|null >
142150 */
143151 private static function parseSliceString (string $ s ): array
144152 {
0 commit comments