55use Exception ;
66use Utopia \Validator ;
77
8- class CLI {
9-
8+ class CLI
9+ {
1010 /**
1111 * Command
1212 *
@@ -153,17 +153,16 @@ public function parse(array $args): array
153153 {
154154 \array_shift ($ args ); // Remove script path from args
155155
156- if (isset ($ args [0 ])) {
156+ if (isset ($ args [0 ])) {
157157 $ this ->command = \array_shift ($ args );
158- }
159- else {
158+ } else {
160159 throw new Exception ('Missing command ' );
161160 }
162161
163162 $ output = [];
164163
165164 foreach ($ args as &$ arg ) {
166- if (\substr ($ arg , 0 , 2 ) === '-- ' ) {
165+ if (\substr ($ arg , 0 , 2 ) === '-- ' ) {
167166 $ arg = \substr ($ arg , 2 );
168167 }
169168 }
@@ -183,14 +182,14 @@ public function run(): self
183182 $ command = isset ($ this ->tasks [$ this ->command ]) ? $ this ->tasks [$ this ->command ] : null ;
184183
185184 try {
186- if ($ command ) {
187- foreach ($ this ->init as $ init ) {
185+ if ($ command ) {
186+ foreach ($ this ->init as $ init ) {
188187 \call_user_func_array ($ init , []);
189188 }
190189
191190 $ params = [];
192191
193- foreach ($ command ->getParams () as $ key => $ param ) {
192+ foreach ($ command ->getParams () as $ key => $ param ) {
194193 // Get value from route or request object
195194 $ value = (isset ($ this ->args [$ key ])) ? $ this ->args [$ key ] : $ param ['default ' ];
196195
@@ -202,15 +201,13 @@ public function run(): self
202201 // Call the callback with the matched positions as params
203202 \call_user_func_array ($ command ->getAction (), $ params );
204203
205- foreach ($ this ->shutdown as $ shutdown ) {
204+ foreach ($ this ->shutdown as $ shutdown ) {
206205 \call_user_func_array ($ shutdown , []);
207206 }
208- }
209- else {
207+ } else {
210208 throw new Exception ('No command found ' );
211209 }
212- }
213- catch (Exception $ e ) {
210+ } catch (Exception $ e ) {
214211 \call_user_func_array ($ this ->error , array ($ e ));
215212 }
216213
@@ -233,7 +230,7 @@ protected function validate(string $key, array $param, $value): void
233230 // checking whether the class exists
234231 $ validator = $ param ['validator ' ];
235232
236- if (\is_callable ($ validator )) {
233+ if (\is_callable ($ validator )) {
237234 $ validator = $ validator ();
238235 }
239236
@@ -245,9 +242,10 @@ protected function validate(string $key, array $param, $value): void
245242 if (!$ validator ->isValid ($ value )) {
246243 throw new Exception ('Invalid ' .$ key . ': ' . $ validator ->getDescription (), 400 );
247244 }
248- }
249- else if (!$ param ['optional ' ]) {
250- throw new Exception ('Param " ' . $ key . '" is not optional. ' , 400 );
245+ } else {
246+ if (!$ param ['optional ' ]) {
247+ throw new Exception ('Param " ' . $ key . '" is not optional. ' , 400 );
248+ }
251249 }
252250 }
253251}
0 commit comments