| Conditions | 7 |
| Paths | 10 |
| Total Lines | 83 |
| Code Lines | 44 |
| 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 |
||
| 41 | public function __invoke( |
||
| 42 | OutputInterface $output, |
||
| 43 | InputInterface $input, |
||
| 44 | #[Option( |
||
| 45 | description: 'The amount of events that are replayed at once (repeated until all events are replayed)', |
||
| 46 | name: 'increments', |
||
| 47 | shortcut: 'i' |
||
| 48 | ) |
||
| 49 | ] |
||
| 50 | int $increments = 1000, |
||
| 51 | ): int { |
||
| 52 | $formatter = new FormatterHelper(); |
||
| 53 | |||
| 54 | // Be careful, when using the no-interaction option you will not get the confirmation question |
||
| 55 | |||
| 56 | if (!in_array($this->environment, ['dev_event_replay', 'prod_event_replay', 'smoketest_event_replay'])) { |
||
| 57 | $output->writeln( |
||
| 58 | $formatter->formatBlock( |
||
| 59 | [ |
||
| 60 | '', |
||
| 61 | 'This command may only be executed using env "dev_event_replay", "prod_event_replay", or |
||
| 62 | "smoketest_event_replay"', |
||
| 63 | '', |
||
| 64 | ], |
||
| 65 | 'error', |
||
| 66 | ), |
||
| 67 | ); |
||
| 68 | |||
| 69 | return 1; |
||
| 70 | } |
||
| 71 | |||
| 72 | $interrogator = new QuestionHelper(); |
||
| 73 | if ($this->environment === 'prod_event_replay') { |
||
| 74 | $wantToRunOnProd = new ConfirmationQuestion( |
||
| 75 | '<question>You have selected to run this on production. Have you disabled all access to the production ' |
||
| 76 | . 'environment? (y/N)</question>', |
||
| 77 | false, |
||
| 78 | ); |
||
| 79 | |||
| 80 | if (!$interrogator->ask($input, $output, $wantToRunOnProd)) { |
||
| 81 | $output->writeln('<comment>Not starting the replay</comment>'); |
||
| 82 | |||
| 83 | return 1; |
||
| 84 | } |
||
| 85 | } |
||
| 86 | if ($increments < 1) { |
||
| 87 | $output->writeln( |
||
| 88 | $formatter->formatBlock( |
||
| 89 | sprintf('Increments must be a positive integer, "%s" given', $increments), |
||
| 90 | 'error', |
||
| 91 | ), |
||
| 92 | ); |
||
| 93 | |||
| 94 | return 1; |
||
| 95 | } |
||
| 96 | |||
| 97 | if ($input->isInteractive()) { |
||
| 98 | $output->writeln(['', $formatter->formatBlock(['', 'WARNING!!!!', ''], 'error'), '']); |
||
| 99 | |||
| 100 | $question = <<<QUESTION |
||
| 101 | You are about to WIPE all read data and recreate all data based on the events present, in steps of %d. |
||
| 102 | |||
| 103 | <%s>>> This can take a while and should not be interrupted <<</%s> |
||
| 104 | |||
| 105 | Are you sure you wish to continue? (y/N) |
||
| 106 | QUESTION; |
||
| 107 | |||
| 108 | $question = sprintf($question, $increments, 'error', 'error'); |
||
| 109 | $areYouSure = new ConfirmationQuestion(sprintf("<question>%s</question>\n", $question), false); |
||
| 110 | if (!$interrogator->ask($input, $output, $areYouSure)) { |
||
| 111 | $output->writeln('<comment>Replay cancelled!</comment>'); |
||
| 112 | |||
| 113 | return 1; |
||
| 114 | } |
||
| 115 | } |
||
| 116 | |||
| 117 | $output->writeln(['', $formatter->formatBlock('Starting Event Replay', 'info')]); |
||
| 118 | $output->writeln( |
||
| 119 | $formatter->formatBlock(' >> If it is interrupted it must be rerun till completed', 'comment'), |
||
| 120 | ); |
||
| 121 | |||
| 122 | $this->replayer->replayEvents($output, $increments); |
||
| 123 | return 0; |
||
| 124 | } |
||
| 126 |