@@ -29,15 +29,15 @@ class Formatter implements Caseable
2929 use HasCastable;
3030 use Makeable;
3131
32- protected $ key_as_string = false ;
32+ protected bool $ key_as_string = false ;
3333
34- protected $ equals_align = false ;
34+ protected bool $ equals_align = false ;
3535
36- protected $ is_simple = false ;
36+ protected bool $ is_simple = false ;
3737
38- protected $ pad_length = 4 ;
38+ protected int $ pad_length = 4 ;
3939
40- protected $ line_break = PHP_EOL ;
40+ protected string $ line_break = PHP_EOL ;
4141
4242 public function setKeyAsString (): void
4343 {
@@ -64,7 +64,8 @@ public function raw(array $array, int $pad = 1): string
6464
6565 $ keys_size = $ this ->sizeKeys ($ array );
6666 $ pad_length = $ this ->pad_length * $ pad ;
67- $ formatted = '[ ' . $ this ->line_break ;
67+
68+ $ formatted = '[ ' . $ this ->line_break ;
6869
6970 foreach ($ array as $ key => $ value ) {
7071 $ key = $ this ->key ($ key , $ keys_size );
@@ -82,14 +83,12 @@ public function raw(array $array, int $pad = 1): string
8283
8384 protected function pad (string $ value , int $ pad = 1 , $ type = STR_PAD_LEFT ): string
8485 {
85- $ pad += $ type === STR_PAD_LEFT
86- ? strlen ($ value )
87- : 2 ;
86+ $ pad += $ type === STR_PAD_LEFT ? strlen ($ value ) : 2 ;
8887
8988 return str_pad ($ value , $ pad , ' ' , $ type );
9089 }
9190
92- protected function value ($ value , int $ pad = 1 )
91+ protected function value ($ value , int $ pad = 1 ): mixed
9392 {
9493 if (! empty ($ value ) && (is_array ($ value ) || is_object ($ value ))) {
9594 return $ this ->raw ($ value , $ pad );
@@ -98,7 +97,7 @@ protected function value($value, int $pad = 1)
9897 return $ this ->castValue ($ value );
9998 }
10099
101- protected function key ($ key , int $ size = 0 )
100+ protected function key (mixed $ key , int $ size = 0 ): string
102101 {
103102 $ key = $ this ->isStringKey ($ key ) ? "' {$ key }' " : $ key ;
104103
@@ -111,20 +110,14 @@ protected function key($key, int $size = 0)
111110
112111 protected function sizeKeys (array $ array ): int
113112 {
114- $ sizes = Arr::longestStringLength (
115- array_keys ($ array )
116- );
113+ $ sizes = Arr::of ($ array )->keys ()->longestStringLength ();
117114
118- return $ this ->key_as_string
119- ? $ sizes + 2
120- : $ sizes ;
115+ return $ this ->key_as_string ? $ sizes + 2 : $ sizes ;
121116 }
122117
123118 protected function keySizeCollision ($ key , int $ size ): int
124119 {
125- $ collision = is_numeric ($ key )
126- ? 0
127- : ($ this ->isAlignAndString () ? -2 : 0 );
120+ $ collision = is_numeric ($ key ) ? 0 : ($ this ->isAlignAndString () ? -2 : 0 );
128121
129122 return $ size + $ collision ;
130123 }
0 commit comments