Conditions | 7 |
Paths | 5 |
Total Lines | 57 |
Lines | 12 |
Ratio | 21.05 % |
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 |
||
88 | protected function execute(InputInterface $input, OutputInterface $output) |
||
89 | { |
||
90 | $availableEvents = $this->collection->getEventNames(); |
||
91 | $availableProjectors = $this->projectorCollection->getProjectorNames(); |
||
92 | |||
93 | View Code Duplication | if ($input->getOption(self::OPTION_LIST_EVENTS)) { |
|
|
|||
94 | $output->writeln('<info>The following events can be replayed:</info>'); |
||
95 | $output->writeln(!empty($availableEvents) ? $availableEvents : 'None.'); |
||
96 | |||
97 | return; |
||
98 | } |
||
99 | |||
100 | View Code Duplication | if ($input->getOption(self::OPTION_LIST_PROJECTORS)) { |
|
101 | $output->writeln('<info>Events can be replayed for the following projectors:</info>'); |
||
102 | $output->writeln(!empty($availableProjectors) ? $availableProjectors : 'None.'); |
||
103 | |||
104 | return; |
||
105 | } |
||
106 | |||
107 | if (count($availableProjectors) === 0) { |
||
108 | $output->writeln('<error>There are no projectors configured to reply events for</error>'); |
||
109 | |||
110 | return; |
||
111 | } |
||
112 | |||
113 | /** @var QuestionHelper $questionHelper */ |
||
114 | $questionHelper = $this->getHelper('question'); |
||
115 | |||
116 | $selectEventsQuestion = new ChoiceQuestion( |
||
117 | 'Which events would you like to replay? Please supply a comma-separated list of numbers.', |
||
118 | $availableEvents |
||
119 | ); |
||
120 | $selectEventsQuestion->setMultiselect(true); |
||
121 | |||
122 | $chosenEvents = $questionHelper->ask($input, $output, $selectEventsQuestion); |
||
123 | $eventSelection = $this->collection->select($chosenEvents); |
||
124 | |||
125 | $selectProjectorsQuestion = new ChoiceQuestion( |
||
126 | 'For which projectors would you like to replay the selected events? ' |
||
127 | . 'Please supply a comma-separated list of numbers.', |
||
128 | $availableProjectors |
||
129 | ); |
||
130 | $selectProjectorsQuestion->setMultiselect(true); |
||
131 | |||
132 | $chosenProjectors = $questionHelper->ask($input, $output, $selectProjectorsQuestion); |
||
133 | $projectorSelection = $this->projectorCollection->selectByNames($chosenProjectors); |
||
134 | |||
135 | $events = $this->pastEventsService->findEventsBy($eventSelection); |
||
136 | |||
137 | $output->writeln('<info>Registering projectors</info>'); |
||
138 | foreach ($projectorSelection as $projector) { |
||
139 | $this->eventDispatcher->registerProjector($projector); |
||
140 | } |
||
141 | |||
142 | $output->writeln('<info>Dispatching events</info>'); |
||
143 | $this->eventDispatcher->dispatch($events); |
||
144 | } |
||
145 | } |
||
146 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.