| Conditions | 20 | 
| Paths | 200 | 
| Total Lines | 93 | 
| Code Lines | 60 | 
| 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 | ||
| 138 | protected function interact(InputInterface $input, OutputInterface $output): void | ||
| 139 |     { | ||
| 140 | $io = new SymfonyStyle($input, $output); | ||
| 141 | $config = Configuration::bootstrapFromCLI($input)->asArray(); | ||
| 142 | $publishersOnly = !empty($config[Configuration::PUBLISHER_JWT_KEY]); | ||
| 143 | $subscribersOnly = !empty($config[Configuration::SUBSCRIBER_JWT_KEY]); | ||
| 144 | $forBothTargets = false === $publishersOnly && false === $subscribersOnly; | ||
| 145 | |||
| 146 |         if (!$forBothTargets && empty($input->getOption('target'))) { | ||
| 147 | $value = $io->choice( | ||
| 148 | 'Do you want to generate a JWT for publishers or subscribers?', | ||
| 149 | [ | ||
| 150 | self::TARGET_PUBLISHERS, | ||
| 151 | self::TARGET_SUBSCRIBERS, | ||
| 152 | ] | ||
| 153 | ); | ||
| 154 | |||
| 155 |             $input->setOption('target', $value); | ||
| 156 | } | ||
| 157 | |||
| 158 |         if ($forBothTargets || self::TARGET_PUBLISHERS === $input->getOption('target')) { | ||
| 159 |             $values = (array) $input->getOption('publish'); | ||
| 160 |             if (empty($values)) { | ||
| 161 | ASK_PUBLISH: | ||
| 162 | $value = $io->ask( | ||
| 163 | 'Add a topic selector for the `publish` key (or just hit ENTER when you\'re done)' | ||
| 164 | ); | ||
| 165 |                 if (null !== $value) { | ||
| 166 | $values[] = $value; | ||
| 167 | goto ASK_PUBLISH; | ||
| 168 | } | ||
| 169 |                 $input->setOption('publish', $values); | ||
| 170 | } | ||
| 171 | |||
| 172 |             $values = (array) $input->getOption('publish-exclude'); | ||
| 173 |             if (empty($values)) { | ||
| 174 | ASK_PUBLISH_EXCLUDE: | ||
| 175 | $value = $io->ask( | ||
| 176 | 'Add a topic selector for the `publish-exclude` key (or just hit ENTER when you\'re done)' | ||
| 177 | ); | ||
| 178 |                 if (null !== $value) { | ||
| 179 | $values[] = $value; | ||
| 180 | goto ASK_PUBLISH_EXCLUDE; | ||
| 181 | } | ||
| 182 |                 $input->setOption('publish-exclude', $values); | ||
| 183 | } | ||
| 184 | } | ||
| 185 | |||
| 186 |         if ($forBothTargets || self::TARGET_SUBSCRIBERS === $input->getOption('target')) { | ||
| 187 |             $values = (array) $input->getOption('subscribe'); | ||
| 188 |             if (empty($values)) { | ||
| 189 | ASK_SUBSCRIBE: | ||
| 190 | $value = $io->ask( | ||
| 191 | 'Add a topic selector for the `subscribe` key (or just hit ENTER when you\'re done)' | ||
| 192 | ); | ||
| 193 |                 if (null !== $value) { | ||
| 194 | $values[] = $value; | ||
| 195 | goto ASK_SUBSCRIBE; | ||
| 196 | } | ||
| 197 |                 $input->setOption('subscribe', $values); | ||
| 198 | } | ||
| 199 | |||
| 200 |             $values = (array) $input->getOption('subscribe-exclude'); | ||
| 201 |             if (empty($values)) { | ||
| 202 | ASK_SUBSCRIBE_EXCLUDE: | ||
| 203 | $value = $io->ask( | ||
| 204 | 'Add a topic selector for the `subscribe-exclude` key (or just hit ENTER when you\'re done)' | ||
| 205 | ); | ||
| 206 |                 if (null !== $value) { | ||
| 207 | $values[] = $value; | ||
| 208 | goto ASK_SUBSCRIBE_EXCLUDE; | ||
| 209 | } | ||
| 210 |                 $input->setOption('subscribe-exclude', $values); | ||
| 211 | } | ||
| 212 | } | ||
| 213 | |||
| 214 |         if (null === $input->getOption('ttl')) { | ||
| 215 | $value = $io->ask( | ||
| 216 | 'TTL of this token in seconds (or hit ENTER for no expiration):', | ||
| 217 | null, | ||
| 218 |                 function ($value) { | ||
| 219 |                     if (null === $value) { | ||
| 220 | return null; | ||
| 221 | } | ||
| 222 |                     if (!\is_numeric($value) || $value <= 0) { | ||
| 223 |                         throw new \RuntimeException('Invalid number.'); | ||
| 224 | } | ||
| 225 | |||
| 226 | return $value; | ||
| 227 | } | ||
| 228 | ); | ||
| 229 | |||
| 230 |             $input->setOption('ttl', $value); | ||
| 231 | } | ||
| 321 |