@@ -10,7 +10,7 @@ trait HasCases
1010 protected $ case = self ::NO_CASE ;
1111
1212 /**
13- * @param int $type
13+ * @param int $type
1414 *
1515 * @throws \Helldar\PrettyArray\Exceptions\UnknownCaseTypeException
1616 */
@@ -23,10 +23,10 @@ public function setCase(int $type = self::NO_CASE): void
2323 $ this ->case = $ type ;
2424 }
2525
26- protected function convertKeysCase (array & $ array ): void
26+ protected function convertKeysCase (array $ array ): array
2727 {
2828 if ($ this ->case === static ::NO_CASE ) {
29- return ;
29+ return $ array ;
3030 }
3131
3232 $ result = [];
@@ -37,7 +37,7 @@ protected function convertKeysCase(array &$array): void
3737 $ result [$ key ] = $ value ;
3838 }
3939
40- $ array = $ result ;
40+ return $ result ;
4141 }
4242
4343 protected function convertKeyCase ($ key )
@@ -47,12 +47,44 @@ protected function convertKeyCase($key)
4747 }
4848
4949 switch ($ this ->case ) {
50+ case static ::KEBAB_CASE :
51+ return $ this ->caseTo (
52+ $ this ->caseTo ($ key , static ::PASCAL_CASE ),
53+ static ::KEBAB_CASE
54+ );
5055 case static ::CAMEL_CASE :
51- return Str::camel ($ key );
56+ return $ this ->caseTo (
57+ $ this ->caseTo ($ key , static ::KEBAB_CASE ),
58+ static ::CAMEL_CASE
59+ );
5260 case static ::SNAKE_CASE :
53- return Str::snake ($ key );
61+ return $ this ->caseTo (
62+ $ this ->caseTo ($ key , static ::PASCAL_CASE ),
63+ static ::SNAKE_CASE
64+ );
65+ case static ::PASCAL_CASE :
66+ return $ this ->caseTo (
67+ $ this ->caseTo ($ key , static ::KEBAB_CASE ),
68+ static ::PASCAL_CASE
69+ );
70+ default :
71+ return $ key ;
72+ }
73+ }
74+
75+ protected function caseTo ($ key , int $ case = 0 )
76+ {
77+ if (! is_string ($ key )) {
78+ return $ key ;
79+ }
80+
81+ switch ($ case ) {
82+ case static ::CAMEL_CASE :
83+ return Str::camel ($ key );
5484 case static ::KEBAB_CASE :
5585 return Str::snake ($ key , '- ' );
86+ case static ::SNAKE_CASE :
87+ return Str::snake ($ key );
5688 case static ::PASCAL_CASE :
5789 return Str::studly ($ key );
5890 default :
0 commit comments