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