| Conditions | 5 |
| Paths | 9 |
| Total Lines | 53 |
| Code Lines | 32 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 3 | ||
| Bugs | 0 | Features | 1 |
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 |
||
| 71 | protected function execute(InputInterface $input, OutputInterface $output) |
||
| 72 | { |
||
| 73 | $questionHelper = $this->getQuestionHelper(); |
||
| 74 | |||
| 75 | if ($input->isInteractive()) { |
||
| 76 | $question = new ConfirmationQuestion($questionHelper->getQuestion('Do you confirm generation', 'yes', '?'), true); |
||
| 77 | if (!$questionHelper->ask($input, $output, $question)) { |
||
| 78 | $output->writeln('<error>Command aborted</error>'); |
||
| 79 | |||
| 80 | return 1; |
||
| 81 | } |
||
| 82 | } |
||
| 83 | |||
| 84 | $entity = Validators::validateEntityName($input->getOption('entity')); |
||
| 85 | list($bundle, $entity) = $this->parseShortcutNotation($entity); |
||
| 86 | |||
| 87 | $format = Validators::validateFormat($input->getOption('format')); |
||
| 88 | $prefix = $this->getRoutePrefix($input, $entity); |
||
| 89 | $withWrite = $input->getOption('with-write'); |
||
| 90 | $forceOverwrite = $input->getOption('overwrite'); |
||
| 91 | |||
| 92 | $questionHelper->writeSection($output, 'REST generation'); |
||
| 93 | |||
| 94 | try { |
||
| 95 | $entityClass = $this->getContainer()->get('doctrine')->getAliasNamespace($bundle).'\\'.$entity; |
||
| 96 | $metadata = $this->getEntityMetadata($entityClass); |
||
| 97 | } catch (\Exception $e) { |
||
| 98 | throw new \RuntimeException(sprintf('Entity "%s" does not exist in the "%s" bundle. Create it with the "doctrine:generate:entity" command and then execute this command again.', $entity, $bundle)); |
||
| 99 | } |
||
| 100 | |||
| 101 | $bundle = $this->getContainer()->get('kernel')->getBundle($bundle); |
||
| 102 | |||
| 103 | $repositoryGenerator = $this->getRepositoryGenerator($bundle); |
||
| 104 | $repositoryGenerator->generate($bundle, $entity, $metadata[0], $format, $forceOverwrite); |
||
| 105 | |||
| 106 | $output->writeln('Generating the Repository pattern code: <info>OK</info>'); |
||
| 107 | |||
| 108 | $generator = $this->getGenerator($bundle); |
||
| 109 | $generator->generate($bundle, $entity, $metadata[0], $format, $prefix, $withWrite, $forceOverwrite); |
||
| 110 | |||
| 111 | $output->writeln('Generating the REST code: <info>OK</info>'); |
||
| 112 | |||
| 113 | $errors = array(); |
||
| 114 | $questionHelper->getRunner($output, $errors); |
||
|
|
|||
| 115 | |||
| 116 | // form |
||
| 117 | if ($withWrite) { |
||
| 118 | $this->generateForm($bundle, $entity, $metadata, $forceOverwrite); |
||
| 119 | $output->writeln('Generating the Form code: <info>OK</info>'); |
||
| 120 | } |
||
| 121 | |||
| 122 | $questionHelper->writeGeneratorSummary($output, $errors); |
||
| 123 | } |
||
| 124 | |||
| 187 |
PHP Analyzer performs a side-effects analysis of your code. A side-effect is basically anything that might be visible after the scope of the method is left.
Let’s take a look at an example:
If we look at the
getEmail()method, we can see that it has no side-effect. Whether you call this method or not, no future calls to other methods are affected by this. As such code as the following is useless:On the hand, if we look at the
setEmail(), this method _has_ side-effects. In the following case, we could not remove the method call: