| Conditions | 9 |
| Paths | 7 |
| Total Lines | 97 |
| 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 |
||
| 107 | protected function interact(InputInterface $input, OutputInterface $output) |
||
| 108 | { |
||
| 109 | $questionHelper = $this->getQuestionHelper(); |
||
|
|
|||
| 110 | $questionHelper->writeSection($output, 'Welcome to the Image entity generator'); |
||
| 111 | |||
| 112 | $message = [ |
||
| 113 | 'This Currently only supports one Image entity', |
||
| 114 | '', |
||
| 115 | ]; |
||
| 116 | |||
| 117 | // If entity already exists, |
||
| 118 | // get overwrite permission |
||
| 119 | if ($this->needsOverWritePermission) { |
||
| 120 | $message[] = sprintf('It looks like the image entity exists as %s', $this->responsiveImageEntity); |
||
| 121 | $message[] = ''; |
||
| 122 | $message[] = sprintf( |
||
| 123 | 'Therefore this generator will overwrite that class, %s', |
||
| 124 | $this->responsiveImageEntity |
||
| 125 | ); |
||
| 126 | |||
| 127 | $output->writeln($message); |
||
| 128 | |||
| 129 | // Ask whether overwrite is allowed |
||
| 130 | $question = $this->createYesNoQuestion($questionHelper, $this->responsiveImageEntity); |
||
| 131 | $overwrite = $questionHelper->ask($input, $output, $question); |
||
| 132 | |||
| 133 | if ($overwrite !== 'y') { |
||
| 134 | throw new \RuntimeException( |
||
| 135 | 'Aborting, overwrite permission is needed.' |
||
| 136 | ); |
||
| 137 | } else { |
||
| 138 | $this->overwrite = true; |
||
| 139 | } |
||
| 140 | } |
||
| 141 | // If class name is not set, |
||
| 142 | // Ask the bundle and the entity name questions |
||
| 143 | elseif (empty($this->responsiveImageEntity)) { |
||
| 144 | $question = new Question( |
||
| 145 | $questionHelper->getQuestion('The bundle name', $input->getOption('bundle')), |
||
| 146 | $input->getOption('bundle') |
||
| 147 | ); |
||
| 148 | |||
| 149 | $question->setValidator(['Sensio\Bundle\GeneratorBundle\Command\Validators', 'validateBundleName']); |
||
| 150 | $question->setNormalizer( |
||
| 151 | function ($value) { |
||
| 152 | return $value ? trim($value) : ''; |
||
| 153 | } |
||
| 154 | ); |
||
| 155 | $question->setMaxAttempts(2); |
||
| 156 | |||
| 157 | $bundle = $questionHelper->ask($input, $output, $question); |
||
| 158 | $input->setOption('bundle', $bundle); |
||
| 159 | |||
| 160 | // Get the Bundle to generate it in |
||
| 161 | $output->writeln( |
||
| 162 | [ |
||
| 163 | '', |
||
| 164 | 'Now, give the name of the new entity class (eg <comment>Image</comment>)', |
||
| 165 | ] |
||
| 166 | ); |
||
| 167 | |||
| 168 | // Get the new class name and validate it. |
||
| 169 | $question = new Question( |
||
| 170 | $questionHelper->getQuestion('The entity name', $input->getOption('entity_name')), |
||
| 171 | $input->getOption('entity_name') |
||
| 172 | ); |
||
| 173 | $question->setValidator( |
||
| 174 | function ($answer) { |
||
| 175 | // Should only contain letters. |
||
| 176 | $valid = preg_match('/^[a-zA-Z]+$/', $answer); |
||
| 177 | if (!$valid) { |
||
| 178 | throw new \RuntimeException( |
||
| 179 | 'The class name should only contain letters' |
||
| 180 | ); |
||
| 181 | } |
||
| 182 | |||
| 183 | return $answer; |
||
| 184 | } |
||
| 185 | ); |
||
| 186 | $question->setNormalizer( |
||
| 187 | function ($value) { |
||
| 188 | return $value ? trim($value) : ''; |
||
| 189 | } |
||
| 190 | ); |
||
| 191 | |||
| 192 | $notificationName = $questionHelper->ask($input, $output, $question); |
||
| 193 | $input->setOption('entity_name', $notificationName); |
||
| 194 | } |
||
| 195 | // Should be all ready to generate |
||
| 196 | |||
| 197 | // At the end we need the bundle and the entity |
||
| 198 | if (empty($this->entityName) || empty($this->bundle)) { |
||
| 199 | throw new \RuntimeException( |
||
| 200 | 'Required options have not been set' |
||
| 201 | ); |
||
| 202 | } |
||
| 203 | } |
||
| 204 | |||
| 338 |
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.