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