33 * @author : Jakiboy
44 * @package : FloatPHP
55 * @subpackage : CLI Component
6- * @version : 1.2 .x
6+ * @version : 1.3 .x
77 * @copyright : (c) 2018 - 2024 Jihad Sinnaour <[email protected] > 88 * @link : https://floatphp.com
99 * @license : MIT
1515
1616namespace FloatPHP \Cli ;
1717
18- use FloatPHP \Classes \Filesystem \{
19- File , Stringify
20- };
18+ use FloatPHP \Classes \Filesystem \{File , Stringify };
2119
2220class BuiltIn
2321{
2422 /**
2523 * @access public
2624 * @return string
2725 */
28- public function help ()
26+ public function help () : never
2927 {
3028 $ this ->getOutput ()->display ('add-page [name] [route] [action] [params] [parent] [method] ' );
3129 $ this ->getOutput ()->display ('add-model [name] ' );
@@ -38,7 +36,7 @@ public function help()
3836 * @param array $args
3937 * @return string
4038 */
41- public function addPage ($ args )
39+ public function addPage ($ args ) : void
4240 {
4341 // Parse name parameter
4442 if ( !($ name = $ this ->parseVars ($ args )) ) {
@@ -73,7 +71,7 @@ public function addPage($args)
7371 // Parse method parameter
7472 $ method = $ this ->parseVars ($ args , 7 ) ? $ this ->parseVars ($ args , 7 ) : 'GET ' ;
7573 $ method = Stringify::uppercase ($ method );
76- $ methods = ['GET ' ,'HEAD ' ,'POST ' ,'PUT ' ,'DELETE ' ,'CONNECT ' ,'OPTIONS ' ,'TRACE ' ,'PATCH ' ];
74+ $ methods = ['GET ' , 'HEAD ' , 'POST ' , 'PUT ' , 'DELETE ' , 'CONNECT ' , 'OPTIONS ' , 'TRACE ' , 'PATCH ' ];
7775 if ( !in_array ($ method , $ methods ) && !Stringify::contains ($ method , '| ' ) ) {
7876 $ this ->getOutput ()->display ("FloatPHP : Command 'add-page' require valid 'method' parameter " );
7977 $ this ->getOutput ()->display ("Use : (GET, POST, PATCH, DELETE, GET|POST) " );
@@ -82,10 +80,10 @@ public function addPage($args)
8280
8381 $ vars = [
8482 'name ' => $ name ,
85- 'route ' => $ route ,
83+ 'route ' => $ route ,
8684 'action ' => $ action ,
8785 'params ' => $ params ,
88- 'parent ' => $ parent ,
86+ 'parent ' => $ parent ,
8987 'method ' => $ method
9088 ];
9189
@@ -100,7 +98,7 @@ public function addPage($args)
10098 * @param array $args
10199 * @return string
102100 */
103- public function addModel ($ args )
101+ public function addModel ($ args ) : void
104102 {
105103 // Parse name parameter
106104 if ( !($ name = $ this ->parseVars ($ args )) ) {
@@ -117,17 +115,17 @@ public function addModel($args)
117115 * @param array $args
118116 * @return void
119117 */
120- private function generateController ($ args )
118+ private function generateController ($ args ) : void
121119 {
122- $ content = File::r (dirname (__FILE__ ). '/bin/controller ' );
120+ $ content = File::r (dirname (__FILE__ ) . '/bin/controller ' );
123121 $ content = Stringify::replaceArray ([
124- '{slug} ' => $ args ['slug ' ],
125- '{name} ' => $ args ['name ' ],
126- '{routeName} ' => $ args ['routeName ' ],
127- '{route} ' => $ args ['route ' ],
128- '{method} ' => $ args ['method ' ],
129- '{action} ' => $ args ['action ' ],
130- '{parent} ' => $ args ['parent ' ],
122+ '{slug} ' => $ args ['slug ' ],
123+ '{name} ' => $ args ['name ' ],
124+ '{routeName} ' => $ args ['routeName ' ],
125+ '{route} ' => $ args ['route ' ],
126+ '{method} ' => $ args ['method ' ],
127+ '{action} ' => $ args ['action ' ],
128+ '{parent} ' => $ args ['parent ' ],
131129 '{params} ' => $ args ['params ' ]
132130 ], $ content );
133131
@@ -139,7 +137,7 @@ private function generateController($args)
139137 * @param array $args
140138 * @return void
141139 */
142- private function generateRoute ($ args )
140+ private function generateRoute ($ args ) : void
143141 {
144142 $ this ->addRoute ([
145143 'method ' => $ args ['method ' ],
@@ -157,26 +155,26 @@ private function generateRoute($args)
157155 private function generateModel ($ name )
158156 {
159157 $ file = "{$ this ->getAppRoot ()}/ {$ this ->getViewPath ()}{$ name }{$ this ->getViewExtension ()}" ;
160- File::w ($ file ,"{$ name } template " );
158+ File::w ($ file , "{$ name } template " );
161159 }
162160
163161 /**
164162 * @access private
165163 * @param array $args
166164 * @return void
167165 */
168- private function generateView ($ name )
166+ private function generateView ($ name ) : void
169167 {
170168 $ file = "{$ this ->getAppRoot ()}/ {$ this ->getViewPath ()}{$ name }{$ this ->getViewExtension ()}" ;
171- File::w ($ file ,"{$ name } template " );
169+ File::w ($ file , "{$ name } template " );
172170 }
173171
174172 /**
175173 * @access private
176174 * @param array $args
177175 * @return array
178176 */
179- private function buildVars ($ args )
177+ private function buildVars ($ args ) : array
180178 {
181179 $ args ['slug ' ] = Stringify::lowercase (Stringify::numberStrip ($ args ['name ' ]));
182180 $ args ['name ' ] = Stringify::capitalize ($ args ['slug ' ]);
@@ -186,7 +184,7 @@ private function buildVars($args)
186184 $ args ['action ' ] = Stringify::lowercase ($ args ['action ' ]);
187185 $ args ['parent ' ] = Stringify::capitalize ($ args ['parent ' ]);
188186 $ args ['method ' ] = Stringify::uppercase ($ args ['method ' ]);
189- if ($ args ['params ' ]) {
187+ if ( $ args ['params ' ] ) {
190188 $ args ['params ' ] = '$ ' . $ args ['params ' ];
191189 $ args ['params ' ] = Stringify::replace (', ' , ',$ ' , $ args ['params ' ]);
192190 }
@@ -199,7 +197,7 @@ private function buildVars($args)
199197 * @param int $pos
200198 * @return mixed
201199 */
202- private function parseVars ($ args , $ pos = 2 )
200+ private function parseVars ($ args , $ pos = 2 ) : mixed
203201 {
204202 return $ args [$ pos ] ?? false ;
205203 }
0 commit comments