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 |
||
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 | |||
100 | if (count($input->getOption('id')) && !in_array($templateKey, $input->getOption('id'))) { |
||
101 | continue; |
||
102 | } |
||
103 | |||
104 | if (null === $currentType || !preg_match(sprintf('#%s#', preg_quote($currentType)), $templateKey)) { |
||
105 | preg_match('#(template\.[^\.]+)#', $templateKey, $matches); |
||
106 | $currentType = isset($matches[1]) ? $matches[1] : $templateKey; |
||
107 | $header = ucwords(str_replace('template.', '', $currentType)); |
||
108 | if ('Init' === $header) { |
||
109 | $header = 'Init repository'; |
||
110 | } elseif ('Ci' === $header) { |
||
111 | $header = 'Continuous integration'; |
||
112 | } |
||
113 | $output->writeln(sprintf('<info>%s%s</info>', $outputLevelSpace, $header)); |
||
114 | } |
||
115 | |||
116 | $output->writeln(sprintf( |
||
117 | '%s* %s : ', |
||
118 | str_repeat($outputLevelSpace, 2), |
||
119 | ucwords(str_replace('template.', '', str_replace($currentType.'.', '', $templateKey))) |
||
120 | )); |
||
121 | if (true === $input->getOption('list')) { |
||
122 | $output->writeln(sprintf( |
||
123 | '%s<comment>Id : </comment><info>%s</info>', |
||
124 | str_repeat($outputLevelSpace, 3), |
||
125 | $templateKey |
||
126 | )); |
||
127 | $output->writeln(sprintf( |
||
128 | '%s<comment>File : </comment><info>%s</info>', |
||
129 | str_repeat($outputLevelSpace, 3), |
||
130 | $templatePath |
||
131 | )); |
||
132 | } else { |
||
133 | $commandProcessor->process($templatePath); |
||
134 | } |
||
135 | } |
||
136 | return 0; |
||
137 | } catch (\Exception $e) { |
||
138 | $output->writeln(sprintf('<error>Error -> %s</error>', $e->getMessage())); |
||
139 | throw $e; |
||
140 | } |
||
141 | } |
||
142 | } |
||
143 |
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.