Conditions | 8 |
Paths | 74 |
Total Lines | 79 |
Code Lines | 51 |
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 |
||
88 | public function replayEvents(OutputInterface $output, $increments) |
||
89 | { |
||
90 | $preparationProgress = new ProgressBar($output, 3); |
||
91 | $preparationProgress->setFormat('event_replay'); |
||
92 | |||
93 | $preparationProgress->setMessage('Starting Transaction'); |
||
94 | $this->connectionHelper->beginTransaction(); |
||
95 | $preparationProgress->advance(); |
||
96 | |||
97 | try { |
||
98 | $preparationProgress->setMessage('Removing data from Read Tables'); |
||
99 | $this->wipeReadTables($output); |
||
100 | $preparationProgress->advance(); |
||
101 | |||
102 | $preparationProgress->setMessage('Determining amount of events to replay...'); |
||
103 | $totalEvents = $this->eventHydrator->getCount(); |
||
104 | |||
105 | $preparationProgress->advance(); |
||
106 | |||
107 | if ($totalEvents == 0) { |
||
108 | // Spaces are needed to overwrite the previous message. |
||
109 | $preparationProgress->setMessage('There are no events to replay. Done. '); |
||
110 | $preparationProgress->finish(); |
||
111 | return; |
||
112 | } else { |
||
113 | $defaultMessage = sprintf( |
||
114 | 'Found <comment>%s</comment> Events, replaying in increments of <comment>%d</comment>', |
||
115 | $totalEvents, |
||
116 | $increments |
||
117 | ); |
||
118 | $preparationProgress->setMessage($defaultMessage); |
||
119 | $preparationProgress->finish(); |
||
120 | } |
||
121 | |||
122 | $replayProgress = new ProgressBar($output, $totalEvents); |
||
123 | $replayProgress->setFormat('event_replay'); |
||
124 | $replayProgress->setMessage($defaultMessage); |
||
125 | |||
126 | for ($count = 0; $count < $totalEvents; $count += $increments) { |
||
127 | /** @var DomainEventStream $eventStream */ |
||
128 | $eventStream = $this->eventHydrator->getFromTill($increments, $count); |
||
129 | |||
130 | if ($output->getVerbosity() >= OutputInterface::VERBOSITY_DEBUG) { |
||
131 | $messages = []; |
||
132 | foreach ($eventStream->getIterator() as $event) { |
||
133 | /** @var DomainMessage $event */ |
||
134 | $messages[] = sprintf( |
||
135 | ' > <info>Publishing Event "<comment>%s</comment>" for UUID <comment>"%s</comment>"</info>', |
||
136 | $event->getType(), |
||
137 | $event->getId() |
||
138 | ); |
||
139 | } |
||
140 | |||
141 | $output->writeln($messages); |
||
142 | } |
||
143 | |||
144 | $this->eventBus->publish($eventStream); |
||
145 | $this->eventBus->flush(); |
||
146 | |||
147 | unset($eventStream); |
||
148 | $steps = (($count + $increments < $totalEvents) ? $increments : ($totalEvents - $count)); |
||
149 | $replayProgress->advance($steps); |
||
150 | } |
||
151 | |||
152 | $this->connectionHelper->commit(); |
||
153 | $replayProgress->finish(); |
||
154 | |||
155 | $output->writeln(['', '<info>Done</info>', '']); |
||
156 | } catch (Exception $e) { |
||
157 | $this->connectionHelper->rollBack(); |
||
158 | if (isset($replayProgress)) { |
||
159 | $replayProgress->setMessage(sprintf('<error>ERROR OCCURRED: "%s"</error>', $e->getMessage())); |
||
160 | $replayProgress->finish(); |
||
161 | } |
||
162 | |||
163 | throw $e; |
||
164 | } |
||
165 | |||
166 | } |
||
167 | |||
205 |