Conditions | 7 |
Paths | 5 |
Total Lines | 57 |
Code Lines | 34 |
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 |
||
68 | protected function execute(InputInterface $input, OutputInterface $output): int |
||
69 | { |
||
70 | $availableEvents = $this->collection->getEventNames(); |
||
71 | $availableProjectors = $this->projectorCollection->getProjectorNames(); |
||
72 | |||
73 | if ($input->getOption(self::OPTION_LIST_EVENTS)) { |
||
74 | $output->writeln('<info>The following events can be replayed:</info>'); |
||
75 | $output->writeln($availableEvents === [] ? 'None.' : $availableEvents); |
||
76 | |||
77 | return 0; |
||
78 | } |
||
79 | |||
80 | if ($input->getOption(self::OPTION_LIST_PROJECTORS)) { |
||
81 | $output->writeln('<info>Events can be replayed for the following projectors:</info>'); |
||
82 | $output->writeln($availableProjectors === [] ? 'None.' : $availableProjectors); |
||
83 | |||
84 | return 0; |
||
85 | } |
||
86 | |||
87 | if ($availableProjectors === []) { |
||
88 | $output->writeln('<error>There are no projectors configured to replay events for</error>'); |
||
89 | |||
90 | return 1; |
||
91 | } |
||
92 | |||
93 | /** @var QuestionHelper $questionHelper */ |
||
94 | $questionHelper = $this->getHelper('question'); |
||
95 | |||
96 | $selectEventsQuestion = new ChoiceQuestion( |
||
97 | 'Which events would you like to replay? Please supply a comma-separated list of numbers.', |
||
98 | $availableEvents, |
||
99 | ); |
||
100 | $selectEventsQuestion->setMultiselect(true); |
||
101 | |||
102 | $chosenEvents = $questionHelper->ask($input, $output, $selectEventsQuestion); |
||
103 | $eventSelection = $this->collection->select($chosenEvents); |
||
104 | |||
105 | $selectProjectorsQuestion = new ChoiceQuestion( |
||
106 | 'For which projectors would you like to replay the selected events? ' |
||
107 | . 'Please supply a comma-separated list of numbers.', |
||
108 | $availableProjectors, |
||
109 | ); |
||
110 | $selectProjectorsQuestion->setMultiselect(true); |
||
111 | |||
112 | $chosenProjectors = $questionHelper->ask($input, $output, $selectProjectorsQuestion); |
||
113 | $projectorSelection = $this->projectorCollection->selectByNames($chosenProjectors); |
||
114 | |||
115 | $events = $this->pastEventsService->findEventsBy($eventSelection); |
||
116 | |||
117 | $output->writeln('<info>Registering projectors</info>'); |
||
118 | foreach ($projectorSelection as $projector) { |
||
119 | $this->eventDispatcher->registerProjector($projector); |
||
120 | } |
||
121 | |||
122 | $output->writeln('<info>Dispatching events</info>'); |
||
123 | $this->eventDispatcher->dispatch($events); |
||
124 | return 0; |
||
125 | } |
||
127 |