@@ -22,13 +22,9 @@ final class Arr implements Iterator, ArrayAccess, Countable
2222{
2323 use Calculable;
2424
25- /** @var array<int|string, mixed> */
26- private array $ arr ;
27-
2825 /** @param array<int|string, mixed> $arr */
29- public function __construct (array $ arr = [])
26+ public function __construct (private array $ arr = [])
3027 {
31- $ this ->arr = $ arr ;
3228 }
3329
3430 public static function fromFunction (callable $ callable , int $ count ): Arr
@@ -111,7 +107,7 @@ public function arr(): array
111107 *
112108 * @param non-empty-string $charNestedKey
113109 */
114- public function get (mixed $ key , mixed $ defaultValue = null , string $ charNestedKey = ". " ): mixed
110+ public function get (int | string $ key , mixed $ defaultValue = null , string $ charNestedKey = ". " ): mixed
115111 {
116112 if (is_string ($ key )) {
117113 $ keyString = strval ($ key );
@@ -137,7 +133,7 @@ public function get(mixed $key, mixed $defaultValue = null, string $charNestedKe
137133 * In the case the $key doesn't exist, an empty Arr can be returned
138134 * @param non-empty-string $charNestedKey
139135 */
140- public function getArr (mixed $ key , mixed $ defaultValue = null , string $ charNestedKey = ". " ): Arr
136+ public function getArr (int | string $ key , mixed $ defaultValue = null , string $ charNestedKey = ". " ): Arr
141137 {
142138 $ value = $ this ->getArrNullable ($ key , $ defaultValue , $ charNestedKey );
143139 if (is_null ($ value )) {
@@ -152,7 +148,7 @@ public function getArr(mixed $key, mixed $defaultValue = null, string $charNeste
152148 * In the case the $key doesn't exist, null can be returned
153149 * @param non-empty-string $charNestedKey
154150 */
155- public function getArrNullable (mixed $ key , mixed $ defaultValue = null , string $ charNestedKey = ". " ): Arr |null
151+ public function getArrNullable (int | string $ key , mixed $ defaultValue = null , string $ charNestedKey = ". " ): Arr |null
156152 {
157153 $ value = $ this ->get ($ key , $ defaultValue , $ charNestedKey );
158154 if (is_null ($ value )) {
@@ -195,7 +191,10 @@ public function set(int|string $key, mixed $value, string $charNestedKey = "."):
195191 $ array = &$ array [$ key ];
196192 }
197193
198- $ array [array_shift ($ keys )] = $ value ;
194+ $ lastKey = array_shift ($ keys );
195+ if ($ lastKey !== null ) {
196+ $ array [$ lastKey ] = $ value ;
197+ }
199198 return ;
200199
201200 }
@@ -205,7 +204,7 @@ public function set(int|string $key, mixed $value, string $charNestedKey = "."):
205204 /**
206205 * Unset an array element by their key if it exists
207206 */
208- public function unset (mixed $ key ): bool
207+ public function unset (int | string $ key ): bool
209208 {
210209 if ($ this ->get ($ key )) {
211210 unset($ this ->arr [$ key ]);
@@ -315,9 +314,9 @@ public function forEach(callable $callback): self
315314 * It returns Arr or [] depending on $returnArrClass value
316315 *
317316 * @param bool $returnArrClass true if you need Arr object
318- * @return int|string| array<int|string, mixed>|Arr
317+ * @return array<int|string, mixed>|Arr
319318 */
320- public function keys (bool $ returnArrClass = false ): int | string | array |Arr
319+ public function keys (bool $ returnArrClass = false ): array |Arr
321320 {
322321 if ($ returnArrClass ) {
323322 return self ::make (array_keys ($ this ->arr ));
@@ -504,8 +503,6 @@ public function some(callable $callback): bool
504503 /**
505504 * Determines whether the array includes a certain value $element among its entries,
506505 * returning true or false as appropriate
507- *
508- * @param int|null $fromIndex
509506 */
510507 public function includes (mixed $ element , ?int $ fromIndex = null ): bool
511508 {
@@ -767,15 +764,14 @@ public function find(callable $callback): mixed
767764 * The copyWithin() method shallow copies part of an array to another
768765 * location in the same array and returns it without modifying its length.
769766 *
770- * @param int|null $end
771767 * @return array<int|string, mixed>
772768 */
773769 public function copyWithin (int $ target , int $ start = 0 , ?int $ end = null ): array
774770 {
775771 $ arrayLength = $ this ->length ();
776772 $ chuck = $ this ->slice ($ start , $ end );
777773 if ($ target < 0 ) {
778- $ target = $ arrayLength - ( int ) abs ($ target );
774+ $ target = $ arrayLength - abs ($ target );
779775 }
780776
781777 foreach ($ chuck as $ value ) {
0 commit comments