| Conditions | 6 |
| Paths | 3 |
| Total Lines | 76 |
| 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 |
||
| 45 | protected function interact(InputInterface $input, OutputInterface $output) |
||
| 46 | { |
||
| 47 | $questionHelper = $this->getQuestionHelper(); |
||
|
|
|||
| 48 | $questionHelper->writeSection($output, 'Welcome to the Notification generator'); |
||
| 49 | |||
| 50 | // Get the Bundle to generate it in |
||
| 51 | $output->writeln( |
||
| 52 | [ |
||
| 53 | 'This command helps you generate a Notification class', |
||
| 54 | '', |
||
| 55 | 'First, give the name of the bundle to generate the notification in (eg <comment>AppBundle</comment>)', |
||
| 56 | ] |
||
| 57 | ); |
||
| 58 | |||
| 59 | $question = new Question( |
||
| 60 | $questionHelper->getQuestion('The bundle name', $input->getOption('bundle')), |
||
| 61 | $input->getOption('bundle') |
||
| 62 | ); |
||
| 63 | |||
| 64 | // @TODO: Add existing bundle validation |
||
| 65 | $question->setValidator(['Sensio\Bundle\GeneratorBundle\Command\Validators', 'validateBundleName']); |
||
| 66 | $question->setNormalizer( |
||
| 67 | function ($value) { |
||
| 68 | return $value ? trim($value) : ''; |
||
| 69 | } |
||
| 70 | ); |
||
| 71 | $question->setMaxAttempts(2); |
||
| 72 | |||
| 73 | $bundle = $questionHelper->ask($input, $output, $question); |
||
| 74 | $input->setOption('bundle', $bundle); |
||
| 75 | |||
| 76 | // Get the Bundle to generate it in |
||
| 77 | $output->writeln( |
||
| 78 | [ |
||
| 79 | '', |
||
| 80 | 'Now, give the name of the new notification class (eg <comment>NewMember</comment>)', |
||
| 81 | ] |
||
| 82 | ); |
||
| 83 | |||
| 84 | // Get the new class name and validate it. |
||
| 85 | $question = new Question( |
||
| 86 | $questionHelper->getQuestion('The notification name', $input->getOption('notification_name')), |
||
| 87 | $input->getOption('notification_name') |
||
| 88 | ); |
||
| 89 | $question->setValidator( |
||
| 90 | function ($answer) { |
||
| 91 | // Should only contain letters. |
||
| 92 | $valid = preg_match('/^[a-zA-Z]+$/', $answer); |
||
| 93 | if (!$valid) { |
||
| 94 | throw new \RuntimeException( |
||
| 95 | 'The class name should only contain letters' |
||
| 96 | ); |
||
| 97 | } |
||
| 98 | |||
| 99 | return $answer; |
||
| 100 | } |
||
| 101 | ); |
||
| 102 | $question->setNormalizer( |
||
| 103 | function ($value) { |
||
| 104 | return $value ? trim($value) : ''; |
||
| 105 | } |
||
| 106 | ); |
||
| 107 | |||
| 108 | $notificationName = $questionHelper->ask($input, $output, $question); |
||
| 109 | $input->setOption('notification_name', $notificationName); |
||
| 110 | |||
| 111 | // ask whether to generate templates for enabled channels. |
||
| 112 | foreach ($this->channels as $channel) { |
||
| 113 | $question = $this->createYesNoQuestion($questionHelper, $input, $channel); |
||
| 114 | |||
| 115 | $generateTemplate = $questionHelper->ask($input, $output, $question); |
||
| 116 | if ($generateTemplate == 'y') { |
||
| 117 | $this->channelTemplates[] = $channel; |
||
| 118 | } |
||
| 119 | } |
||
| 120 | } |
||
| 121 | |||
| 203 | } |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.