@@ -282,9 +282,15 @@ public function getCommandsList(): array
282
282
);
283
283
284
284
foreach ($ files as $ file ) {
285
- //Remove "Command.php" from filename
286
- $ command = $ this ->classNameToCommandName (substr ($ file ->getFilename (), 0 , -4 ));
285
+ // Convert filename to command
286
+ $ command = $ this ->classNameToCommandName (substr ($ file ->getFilename (), 0 , -4 ));
287
287
288
+ // Invalid Classname
289
+ if (is_null ($ command )) {
290
+ continue ;
291
+ }
292
+
293
+ // Already registered
288
294
if (array_key_exists ($ command , $ commands )) {
289
295
continue ;
290
296
}
@@ -318,6 +324,12 @@ public function getCommandsList(): array
318
324
public function getCommandClassName (string $ auth , string $ command , string $ filepath = '' ): ?string
319
325
{
320
326
$ command = mb_strtolower ($ command );
327
+
328
+ // Invalid command
329
+ if (trim ($ command ) === '' ) {
330
+ return null ;
331
+ }
332
+
321
333
$ auth = $ this ->ucFirstUnicode ($ auth );
322
334
323
335
// First, check for directly assigned command class.
@@ -1290,14 +1302,15 @@ public function getUpdateFilter(): ?callable
1290
1302
*
1291
1303
* @param string $class For example FooBarCommand
1292
1304
*
1293
- * @return string for example foo_bar. In case of errors, returns an empty string
1305
+ * @return string|null for example foo_bar. In case of errors, returns null.
1294
1306
*/
1295
- protected function classNameToCommandName (string $ class ): string
1307
+ protected function classNameToCommandName (string $ class ): ? string
1296
1308
{
1297
- // 7 is the length of 'Command'
1309
+ // If $class doesn't end with 'Command'
1298
1310
if (substr ($ class , -7 ) !== 'Command ' ) {
1299
- return '' ;
1311
+ return null ;
1300
1312
}
1313
+
1301
1314
return mb_strtolower (preg_replace ('/(.)(?=[\p{Lu}])/u ' , '$1_ ' , substr ($ class , 0 , -7 )));
1302
1315
}
1303
1316
@@ -1306,13 +1319,14 @@ protected function classNameToCommandName(string $class): string
1306
1319
*
1307
1320
* @param string $command For example foo_bar
1308
1321
*
1309
- * @return string for example FooBarCommand. In case of errors, returns an empty string
1322
+ * @return string|null for example FooBarCommand. In case of errors, returns null.
1310
1323
*/
1311
- protected function commandNameToClassName (string $ command ): string
1324
+ protected function commandNameToClassName (string $ command ): ? string
1312
1325
{
1313
- if ($ command === '' ) {
1314
- return '' ;
1326
+ if (trim ( $ command) === '' ) {
1327
+ return null ;
1315
1328
}
1329
+
1316
1330
return str_replace (' ' , '' , $ this ->ucWordsUnicode (str_replace ('_ ' , ' ' , $ command ))) . 'Command ' ;
1317
1331
}
1318
1332
}
0 commit comments