Conditions | 6 |
Paths | 37 |
Total Lines | 70 |
Code Lines | 45 |
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 |
||
44 | public function run(Collection $migrations, OutputStyle $deployCommandOutput) |
||
45 | { |
||
46 | foreach ($migrations as $migration) { |
||
47 | $outputs = []; |
||
48 | $currentMigration = $migration; |
||
49 | $currentCommand = null; |
||
50 | |||
51 | try { |
||
52 | $this->connection->beginTransaction(); |
||
53 | |||
54 | $tableQuery = $this->getTableQuery(); |
||
55 | |||
56 | $alreadyExecuted = $tableQuery->where('migration', '=', get_class($migration))->count() > 0; |
||
57 | |||
58 | if ($alreadyExecuted === true) { |
||
59 | continue; |
||
60 | } |
||
61 | |||
62 | $commands = $migration->getCommands(); |
||
63 | |||
64 | foreach ($commands as $commandName => $arguments) { |
||
65 | $currentCommand = $commandName; |
||
66 | |||
67 | $signature = $this->getSignature($commandName); |
||
68 | |||
69 | Artisan::call($signature, $arguments); |
||
70 | $output = Artisan::output(); |
||
71 | |||
72 | $outputs[$commandName] = $output; |
||
73 | } |
||
74 | |||
75 | $deployCommandOutput->progressAdvance(); |
||
76 | |||
77 | $tableQuery->insert([ |
||
78 | 'migration' => get_class($migration), |
||
79 | 'created_at' => Carbon::now() |
||
80 | |||
81 | ]); |
||
82 | |||
83 | $this->getInfoTableQuery()->insert([ |
||
84 | 'migration' => get_class($migration), |
||
85 | 'output' => json_encode($outputs), |
||
86 | 'created_at' => Carbon::now() |
||
87 | ]); |
||
88 | |||
89 | $this->connection->commit(); |
||
90 | } catch (\Throwable $e) { |
||
91 | $migrationClass = $currentMigration !== null ? get_class($currentMigration) : null; |
||
92 | $commandClass = $currentCommand; |
||
93 | |||
94 | $deployCommandOutput->writeln(''); |
||
95 | $deployCommandOutput->writeln(sprintf('<error>Error during %s migration; %s command</error>', $migrationClass, $commandClass)); |
||
96 | $deployCommandOutput->writeln(sprintf('<error>%s</error>', (string)$e)); |
||
97 | $this->connection->rollBack(); |
||
98 | |||
99 | $this->getInfoTableQuery()->insert([ |
||
100 | 'migration' => $migrationClass, |
||
101 | 'output' => json_encode($outputs), |
||
102 | 'error' => json_encode([ |
||
103 | 'trace' => $e->getTraceAsString(), |
||
104 | 'message' => $e->getMessage(), |
||
105 | 'code' => $e->getCode(), |
||
106 | 'file' => $e->getFile(), |
||
107 | 'line' => $e->getLine(), |
||
108 | 'error_command' => $commandClass |
||
109 | ]), |
||
110 | 'created_at' => Carbon::now() |
||
111 | ]); |
||
112 | |||
113 | throw $e; |
||
114 | } |
||
149 | } |