Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
1 | <?php |
||
16 | class InputAssistant |
||
17 | { |
||
18 | /** @var InputInterface */ |
||
19 | private $input; |
||
20 | |||
21 | /** @var OutputInterface */ |
||
22 | private $output; |
||
23 | |||
24 | /** @var QuestionHelper */ |
||
25 | private $questionHelper; |
||
26 | |||
27 | /** @var Kernel */ |
||
28 | private $kernel; |
||
29 | |||
30 | /** @var ContainerInterface */ |
||
31 | private $container; |
||
32 | |||
33 | /** |
||
34 | * @param InputInterface $input |
||
35 | * @param OutputInterface $output |
||
36 | * @param QuestionHelper $questionHelper |
||
37 | * @param Kernel $kernel |
||
38 | * @param ContainerInterface $container |
||
39 | */ |
||
40 | public function __construct(InputInterface &$input, OutputInterface $output, QuestionHelper $questionHelper, Kernel $kernel, ContainerInterface $container) |
||
48 | |||
49 | /** |
||
50 | * Asks for the namespace and sets it on the InputInterface as the 'namespace' option, if this option is not set yet. |
||
51 | * |
||
52 | * @param array $text what you want printed before the namespace is asked |
||
|
|||
53 | * |
||
54 | * @return string The namespace. But it's also been set on the InputInterface. |
||
55 | */ |
||
56 | public function askForNamespace(array $text = null) |
||
101 | |||
102 | /** |
||
103 | * Helper function to display errors in the console. |
||
104 | * |
||
105 | * @param $message |
||
106 | * @param bool $exit |
||
107 | */ |
||
108 | View Code Duplication | private function writeError($message, $exit = false) |
|
115 | |||
116 | /** |
||
117 | * Get an array with all the bundles the user has created. |
||
118 | * |
||
119 | * @return array |
||
120 | */ |
||
121 | public function getOwnBundles() |
||
145 | |||
146 | /** |
||
147 | * Returns a list of namespaces as array with a forward slash to split the namespace & bundle. |
||
148 | * |
||
149 | * @param Kernel $kernel |
||
150 | * |
||
151 | * @return array |
||
152 | */ |
||
153 | private function getNamespaceAutoComplete(Kernel $kernel) |
||
162 | |||
163 | /** |
||
164 | * Replaces '\' with '/'. |
||
165 | * |
||
166 | * @param $namespace |
||
167 | * |
||
168 | * @return mixed |
||
169 | */ |
||
170 | private function fixNamespace($namespace) |
||
174 | |||
175 | /** |
||
176 | * Asks for the prefix and sets it on the InputInterface as the 'prefix' option, if this option is not set yet. |
||
177 | * Will set the default to a snake_cased namespace when the namespace has been set on the InputInterface. |
||
178 | * |
||
179 | * @param array $text What you want printed before the prefix is asked. If null is provided it'll write a default text. |
||
180 | * @param string $namespace An optional namespace. If this is set it'll create the default based on this prefix. |
||
181 | * If it's not provided it'll check if the InputInterface already has the namespace option. |
||
182 | * |
||
183 | * @return string The prefix. But it's also been set on the InputInterface. |
||
184 | */ |
||
185 | public function askForPrefix(array $text = null, $namespace = null) |
||
230 | |||
231 | /** |
||
232 | * Converts something like Namespace\BundleNameBundle to namspace_bundlenamebundle. |
||
233 | * |
||
234 | * @param string $namespace |
||
235 | * |
||
236 | * @return string |
||
237 | */ |
||
238 | View Code Duplication | private function convertNamespaceToSnakeCase($namespace) |
|
246 | } |
||
247 |
This check looks for
@param
annotations where the type inferred by our type inference engine differs from the declared type.It makes a suggestion as to what type it considers more descriptive. In addition it looks for parameters that have the generic type
array
and suggests a stricter type likearray<String>
.Most often this is a case of a parameter that can be null in addition to its declared types.