| Conditions | 8 |
| Paths | 16 |
| Total Lines | 54 |
| Code Lines | 27 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 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 namespace crocodicstudio\crudbooster\commands; |
||
| 47 | private function generateSeeder() { |
||
| 48 | set_time_limit(120); |
||
| 49 | $tables = DB::connection()->getDoctrineSchemaManager()->listTableNames(); |
||
| 50 | $php_string = ""; |
||
| 51 | $additional_tables = cbConfig("ADDITIONAL_DATA_MIGRATION"); |
||
| 52 | |||
| 53 | foreach($tables as $table) { |
||
| 54 | if(substr($table,0,3) == "cb_" || in_array($table, $additional_tables)) { |
||
| 55 | $this->info("Create seeder for table : ".$table); |
||
| 56 | $rows = DB::table($table)->get(); |
||
| 57 | $data = []; |
||
| 58 | foreach($rows as $i=>$row) { |
||
| 59 | $data[$i] = []; |
||
| 60 | foreach($row as $key=>$val) { |
||
| 61 | $data[$i][$key] = $val; |
||
| 62 | } |
||
| 63 | } |
||
| 64 | if(count($data)!=0) { |
||
| 65 | $php_string .= 'DB::table(\''.$table.'\')->delete();'."\n\t\t\t"; |
||
| 66 | $php_string .= 'DB::table(\''.$table.'\')->insert('.min_var_export($data).');'."\n\t\t\t"; |
||
| 67 | } |
||
| 68 | } |
||
| 69 | } |
||
| 70 | $seederFileTemplate = ' |
||
| 71 | <?php |
||
| 72 | use Illuminate\Database\Seeder; |
||
| 73 | use Illuminate\Support\Facades\DB; |
||
| 74 | class CbMigrationSeeder extends Seeder |
||
| 75 | { |
||
| 76 | public function run() |
||
| 77 | { |
||
| 78 | $this->command->info(\'Please wait updating the data...\'); |
||
| 79 | $this->call(\'CbMigrationData\'); |
||
| 80 | $this->command->info(\'Updating the data completed !\'); |
||
| 81 | } |
||
| 82 | } |
||
| 83 | class CbMigrationData extends Seeder { |
||
| 84 | public function run() { |
||
| 85 | '.$php_string.' |
||
| 86 | } |
||
| 87 | } |
||
| 88 | '; |
||
| 89 | file_put_contents(base_path('database/seeds/CbMigrationSeeder.php'), $seederFileTemplate); |
||
| 90 | |||
| 91 | $composer_path = ''; |
||
| 92 | if (file_exists(getcwd().'/composer.phar')) { |
||
| 93 | $composer_path = '"'.PHP_BINARY.'" '.getcwd().'/composer.phar'; |
||
| 94 | }else{ |
||
| 95 | $composer_path = 'composer'; |
||
| 96 | } |
||
| 97 | |||
| 98 | $this->info('Dumping auto loads new file seeder !'); |
||
| 99 | $process = new Process($composer_path.' dump-autoload'); |
||
|
|
|||
| 100 | $process->setWorkingDirectory(base_path())->run(); |
||
| 101 | |||
| 104 |