Conditions | 2 |
Paths | 3 |
Total Lines | 78 |
Code Lines | 49 |
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 |
||
152 | protected function interact(InputInterface $input, OutputInterface $output) |
||
153 | { |
||
154 | $questionHelper = $this->getQuestionHelper(); |
||
155 | $questionHelper->writeSection($output, 'Welcome to the Doctrine2 CRUD generator'); |
||
156 | |||
157 | // namespace |
||
158 | $output->writeln( |
||
159 | [ |
||
160 | '', |
||
161 | 'This command helps you generate CRUD controllers and templates.', |
||
162 | '', |
||
163 | 'First, give the name of the existing entity for which you want to generate a CRUD', |
||
164 | '(use the shortcut notation like <comment>AcmeBlogBundle:Post</comment>)', |
||
165 | '', |
||
166 | ] |
||
167 | ); |
||
168 | |||
169 | // list($bundle, $entity) = $this->parseShortcutNotation($entity); |
||
170 | $entity = $this->entityName; |
||
171 | $bundle = $this->bundle; |
||
172 | try { |
||
173 | $entityClass = $this->getContainer()->get('doctrine')->getAliasNamespace($bundle) . '\\' . $entity; |
||
174 | $metadata = $this->getEntityMetadata($entityClass); |
||
175 | } catch (\Exception $e) { |
||
176 | throw new \RuntimeException( |
||
177 | sprintf( |
||
178 | 'Entity "%s" does not exist in the "%s" bundle. You may have mistyped the bundle name or maybe the entity doesn\'t exist yet (create it first with the "doctrine:generate:entity" command).', |
||
179 | $entity, |
||
180 | $bundle |
||
181 | ) |
||
182 | ); |
||
183 | } |
||
184 | |||
185 | // format |
||
186 | $format = $input->getOption('format'); |
||
187 | $output->writeln( |
||
188 | [ |
||
189 | '', |
||
190 | 'Determine the format to use for the generated CRUD.', |
||
191 | '', |
||
192 | ] |
||
193 | ); |
||
194 | $question = new Question( |
||
195 | $questionHelper->getQuestion('Configuration format (yml, xml, php, or annotation)', $format), $format |
||
196 | ); |
||
197 | $question->setValidator(['Sensio\Bundle\GeneratorBundle\Command\Validators', 'validateFormat']); |
||
198 | $format = $questionHelper->ask($input, $output, $question); |
||
199 | $input->setOption('format', $format); |
||
200 | |||
201 | // route prefix |
||
202 | $prefix = $this->getRoutePrefix($input, $entity); |
||
203 | $output->writeln( |
||
204 | [ |
||
205 | '', |
||
206 | 'Determine the routes prefix (all the routes will be "mounted" under this', |
||
207 | 'prefix: /prefix/, /prefix/new, ...).', |
||
208 | '', |
||
209 | ] |
||
210 | ); |
||
211 | $prefix = $questionHelper->ask( |
||
212 | $input, |
||
213 | $output, |
||
214 | new Question($questionHelper->getQuestion('Routes prefix', '/' . $prefix), '/' . $prefix) |
||
215 | ); |
||
216 | $input->setOption('route-prefix', $prefix); |
||
217 | |||
218 | // summary |
||
219 | $output->writeln( |
||
220 | [ |
||
221 | '', |
||
222 | $this->getHelper('formatter')->formatBlock('Summary before generation', 'bg=blue;fg=white', true), |
||
223 | '', |
||
224 | sprintf('You are going to generate a CRUD controller for "<info>%s:%s</info>"', $bundle, $entity), |
||
225 | sprintf('using the "<info>%s</info>" format.', $format), |
||
226 | '', |
||
227 | ] |
||
228 | ); |
||
229 | } |
||
230 | |||
245 | } |
An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.
If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.