| Conditions | 15 |
| Paths | 385 |
| Total Lines | 86 |
| Code Lines | 62 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 0 |
| CRAP Score | 240 |
| 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 |
||
| 55 | protected function execute(InputInterface $input, OutputInterface $output) |
||
| 56 | { |
||
| 57 | $outputLevelSpace = ' '; |
||
| 58 | |||
| 59 | $mode = $input->getArgument('type'); |
||
| 60 | |||
| 61 | if (!in_array($mode, [Mode::PHP_LIBRARY, Mode::SYMFONY_LIBRARY, Mode::PROJECT])) { |
||
| 62 | $output->writeln(sprintf('<error>Unexpected mode "%s" !</error>', $mode)); |
||
| 63 | $output->writeln('<info>Allowed mode :</info>'); |
||
| 64 | $output->writeln(sprintf('%s<comment>%s</comment>', $outputLevelSpace, Mode::PHP_LIBRARY)); |
||
| 65 | $output->writeln(sprintf('%s<comment>%s</comment>', $outputLevelSpace, Mode::SYMFONY_LIBRARY)); |
||
| 66 | $output->writeln(sprintf('%s<comment>%s</comment>', $outputLevelSpace, Mode::PROJECT)); |
||
| 67 | |||
| 68 | return 1; |
||
| 69 | } |
||
| 70 | |||
| 71 | $variableBag = (new VariableBagFactory())->load($mode); |
||
| 72 | $templatePathList = (new TemplatePathBagFactory())->load($mode); |
||
| 73 | |||
| 74 | $skipExistingFile = false === $input->getOption('ask-before-override'); |
||
| 75 | $forceOverride = $input->getOption('force-override'); |
||
| 76 | if (true === $forceOverride) { |
||
| 77 | $skipExistingFile = false; |
||
| 78 | } |
||
| 79 | |||
| 80 | $commandTemplateHelper = new CommandTemplateHelper( |
||
| 81 | $this->getHelper('question'), |
||
|
1 ignored issue
–
show
|
|||
| 82 | $input, |
||
| 83 | $output, |
||
| 84 | $variableBag->all(), |
||
| 85 | $skipExistingFile, |
||
| 86 | $forceOverride |
||
| 87 | ); |
||
| 88 | $commandProcessor = new CommandTemplateProcessor($commandTemplateHelper); |
||
| 89 | |||
| 90 | $output->writeln(sprintf('<comment>Creating default files for : </comment><info>%s</info>', ucwords($mode))); |
||
| 91 | if (true === $forceOverride) { |
||
| 92 | $output->writeln('<fg=red>WARNING : Existing files will be overriden by default</fg=red>'); |
||
| 93 | } elseif (true === $skipExistingFile) { |
||
| 94 | $output->writeln('<comment>INFO : Existing files will be skipped !</comment>'); |
||
| 95 | } |
||
| 96 | try { |
||
| 97 | $currentType = null; |
||
| 98 | foreach ($templatePathList as $templateKey => $templatePath) { |
||
| 99 | if (count($input->getOption('id')) && !in_array($templateKey, $input->getOption('id'))) { |
||
| 100 | continue; |
||
| 101 | } |
||
| 102 | |||
| 103 | if (null === $currentType || !preg_match(sprintf('#%s#', preg_quote($currentType)), $templateKey)) { |
||
| 104 | preg_match('#(template\.[^\.]+)#', $templateKey, $matches); |
||
| 105 | $currentType = isset($matches[1]) ? $matches[1] : $templateKey; |
||
| 106 | $header = ucwords(str_replace('template.', '', $currentType)); |
||
| 107 | if ('Init' === $header) { |
||
| 108 | $header = 'Init repository'; |
||
| 109 | } elseif ('Ci' === $header) { |
||
| 110 | $header = 'Continuous integration'; |
||
| 111 | } |
||
| 112 | $output->writeln(sprintf('<info>%s%s</info>', $outputLevelSpace, $header)); |
||
| 113 | } |
||
| 114 | |||
| 115 | $output->writeln(sprintf( |
||
| 116 | '%s* %s : ', |
||
| 117 | str_repeat($outputLevelSpace, 2), |
||
| 118 | ucwords(str_replace('template.', '', str_replace($currentType.'.', '', $templateKey))) |
||
| 119 | )); |
||
| 120 | if (true === $input->getOption('list')) { |
||
| 121 | $output->writeln(sprintf( |
||
| 122 | '%s<comment>Id : </comment><info>%s</info>', |
||
| 123 | str_repeat($outputLevelSpace, 3), |
||
| 124 | $templateKey |
||
| 125 | )); |
||
| 126 | $output->writeln(sprintf( |
||
| 127 | '%s<comment>File : </comment><info>%s</info>', |
||
| 128 | str_repeat($outputLevelSpace, 3), |
||
| 129 | $templatePath |
||
| 130 | )); |
||
| 131 | } else { |
||
| 132 | $commandProcessor->process($templatePath); |
||
| 133 | } |
||
| 134 | } |
||
| 135 | return 0; |
||
| 136 | } catch (\Exception $e) { |
||
| 137 | $output->writeln(sprintf('<error>Error -> %s</error>', $e->getMessage())); |
||
| 138 | throw $e; |
||
| 139 | } |
||
| 140 | } |
||
| 141 | } |
||
| 142 |
This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.
Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.