Conditions | 8 |
Paths | 11 |
Total Lines | 51 |
Code Lines | 31 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
28 | public function handle() |
||
29 | { |
||
30 | $package = Str::lower($this->argument('package')); |
||
|
|||
31 | if (! $this->packagist->checkFormat($package)) { |
||
32 | $this->error('Package name format must be vendor/package'); |
||
33 | |||
34 | return 1; |
||
35 | } |
||
36 | |||
37 | if (! $this->storage->exists($package)) { |
||
38 | $this->error('Package does not exists'); |
||
39 | |||
40 | return 1; |
||
41 | } |
||
42 | |||
43 | $tables = $this->getPackageTables($package); |
||
44 | |||
45 | if (empty($tables)) { |
||
46 | $this->error('No table creation in the package'); |
||
47 | |||
48 | return 1; |
||
49 | } |
||
50 | |||
51 | foreach ($tables as $table) { |
||
52 | foreach (Schema::getConnection()->getDoctrineSchemaManager()->listTableForeignKeys($table) as $fk) { |
||
53 | if (in_array($fk->getForeignTableName(), $tables)) { |
||
54 | continue; |
||
55 | } |
||
56 | |||
57 | $model = Str::studly(Str::singular($fk->getForeignTableName())); |
||
58 | $namespaces[$fk->getForeignTableName()] = $this->checkModel($model); |
||
59 | } |
||
60 | } |
||
61 | |||
62 | $warn = ' Warning ! This command will overwrite all files in the package '.$package.' '; |
||
63 | $this->warn(str_repeat('*', strlen($warn))); |
||
64 | $this->warn($warn); |
||
65 | $this->warn(str_repeat('*', strlen($warn))); |
||
66 | |||
67 | if (! $this->confirm('Confirm?')) { |
||
68 | return 0; |
||
69 | } |
||
70 | |||
71 | $args = ['tables' => $tables, 'package' => $package]; |
||
72 | $this->callCommand('model', array_merge_recursive($args, ['namespaces' => $namespaces])); |
||
73 | $this->callCommand('routes', $args); |
||
74 | $this->callCommand('lang', $args); |
||
75 | $this->callCommand('permissions', $args); |
||
76 | $this->callCommand('controller', array_merge_recursive($args, ['namespaces' => $namespaces])); |
||
77 | $this->callCommand('menu', $args); |
||
78 | $this->callCommand('views', $args); |
||
79 | } |
||
120 |