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