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 |
||
33 | class ExampleCommands extends \Robo\Tasks |
||
34 | { |
||
35 | /** |
||
36 | * Watch a file. |
||
37 | * |
||
38 | * Demonstrates the 'watch' command. Runs 'composer update' any time |
||
39 | * composer.json changes. |
||
40 | */ |
||
41 | public function tryWatch() |
||
47 | |||
48 | /** |
||
49 | * Demonstrates Robo input APIs. |
||
50 | */ |
||
51 | public function tryInput() |
||
66 | |||
67 | /** |
||
68 | * Demonstrate Robo configuration. |
||
69 | * |
||
70 | * Config values are loaded from the followig locations: |
||
71 | * |
||
72 | * - [Robo Project]/robo.yml |
||
73 | * - $HOME/.robo/robo.yml |
||
74 | * - $CWD/robo.yml |
||
75 | * - Environment variables ROBO_CONFIG_KEY (e.g. ROBO_OPTIONS_PROGRESS_DELAY) |
||
76 | * - Overridden on the commandline via -Doptions.progress-delay=value |
||
77 | * |
||
78 | * @param string $key Name of the option to read (e.g. options.progress-delay) |
||
79 | * @option opt An option whose value is printed. Can be overridden in |
||
80 | * configuration via the configuration key command.try.config.options.opt. |
||
81 | * @option show-all Also print out the value of all configuration options |
||
82 | */ |
||
83 | public function tryConfig($key = 'options.progress-delay', $options = ['opt' => '0', 'show-all' => false]) |
||
94 | |||
95 | /** |
||
96 | * Demonstrates serial execution. |
||
97 | * |
||
98 | * @option $printed Print the output of each process. |
||
99 | * @option $error Include an extra process that fails. |
||
100 | */ |
||
101 | public function tryExec($options = ['printed' => true, 'error' => false]) |
||
118 | |||
119 | /** |
||
120 | * Demonstrates parallel execution. |
||
121 | * |
||
122 | * @option $printed Print the output of each process. |
||
123 | * @option $error Include an extra process that fails. |
||
124 | */ |
||
125 | public function tryPara($options = ['printed' => true, 'error' => false]) |
||
139 | |||
140 | /** |
||
141 | * try:opt-required |
||
142 | */ |
||
143 | public function tryOptRequired($options = ['foo' => InputOption::VALUE_REQUIRED]) |
||
147 | |||
148 | /** |
||
149 | * Demonstrates Robo argument passing. |
||
150 | * |
||
151 | * @param string $a The first parameter. Required. |
||
152 | * @param string $b The second parameter. Optional. |
||
153 | */ |
||
154 | public function tryArgs($a, $b = 'default') |
||
158 | |||
159 | /** |
||
160 | * Demonstrate Robo variable argument passing. |
||
161 | * |
||
162 | * @param array $a A list of commandline parameters. |
||
163 | * @param array $options |
||
164 | */ |
||
165 | public function tryArrayArgs(array $a, array $options = ['foo' => []]) |
||
172 | |||
173 | /** |
||
174 | * Demonstrate use of SymfonyStyle $io object and Symfony $input object in |
||
175 | * Robo in place of the usual "parameter arguments". |
||
176 | * |
||
177 | * @arg array $a A list of commandline parameters. |
||
178 | * @option foo |
||
179 | * @default a [] |
||
180 | * @default foo [] |
||
181 | */ |
||
182 | View Code Duplication | public function trySymfony(SymfonyStyle $io, InputInterface $input) |
|
192 | |||
193 | public function tryText() |
||
199 | |||
200 | /** |
||
201 | * Demonstrate Robo boolean options. |
||
202 | * |
||
203 | * @param $opts The options. |
||
204 | * @option boolean $silent Supress output. |
||
205 | */ |
||
206 | public function tryOptbool($opts = ['silent|s' => false]) |
||
212 | |||
213 | /** |
||
214 | * Demonstrate the use of the PHP built-in webserver. |
||
215 | */ |
||
216 | public function tryServer() |
||
223 | |||
224 | /** |
||
225 | * Demonstrate the use of the Robo open-browser task. |
||
226 | */ |
||
227 | public function tryOpenBrowser() |
||
234 | |||
235 | /** |
||
236 | * Demonstrate Robo error output and command failure. |
||
237 | */ |
||
238 | public function tryError() |
||
242 | |||
243 | /** |
||
244 | * Demonstrate Robo standard output and command success. |
||
245 | */ |
||
246 | public function trySuccess() |
||
250 | |||
251 | /** |
||
252 | * @field-labels |
||
253 | * name: Name |
||
254 | * species: Species |
||
255 | * legs: Legs |
||
256 | * food: Favorite Food |
||
257 | * id: Id |
||
258 | * @return PropertyList |
||
259 | */ |
||
260 | public function tryInfo() |
||
288 | |||
289 | /** |
||
290 | * Demonstrate Robo formatters. Default format is 'table'. |
||
291 | * |
||
292 | * @field-labels |
||
293 | * first: I |
||
294 | * second: II |
||
295 | * third: III |
||
296 | * @default-string-field second |
||
297 | * @usage try:formatters --format=yaml |
||
298 | * @usage try:formatters --format=csv |
||
299 | * @usage try:formatters --fields=first,third |
||
300 | * @usage try:formatters --fields=III,II |
||
301 | * @aliases tf |
||
302 | * |
||
303 | * @return \Consolidation\OutputFormatters\StructuredData\RowsOfFields |
||
304 | */ |
||
305 | public function tryFormatters($somthing = 'default', $options = ['format' => 'table', 'fields' => '']) |
||
315 | |||
316 | /** |
||
317 | * Try word wrapping |
||
318 | * |
||
319 | * @field-labels |
||
320 | * first: First |
||
321 | * second: Second |
||
322 | * |
||
323 | * @return \Consolidation\OutputFormatters\StructuredData\RowsOfFields |
||
324 | */ |
||
325 | public function tryWrap() |
||
335 | |||
336 | /** |
||
337 | * Demonstrate an alter hook with an option |
||
338 | * |
||
339 | * @hook alter try:formatters |
||
340 | * @option $french Add a row with French numbers. |
||
341 | * @usage try:formatters --french |
||
342 | */ |
||
343 | public function alterFormatters($result, CommandData $commandData) |
||
351 | |||
352 | /** |
||
353 | * Demonstrate what happens when a command or a task |
||
354 | * throws an exception. Note that typically, Robo commands |
||
355 | * should return Result objects rather than throw exceptions. |
||
356 | */ |
||
357 | public function tryException($options = ['task' => false]) |
||
364 | |||
365 | /** |
||
366 | * Demonstrate deprecated task behavior. |
||
367 | * |
||
368 | * Demonstrate what happens when using a task that is created via |
||
369 | * direct instantiation, which omits initialization done by the |
||
370 | * container. Emits a warning message. |
||
371 | */ |
||
372 | public function tryDeprecated() |
||
379 | |||
380 | /** |
||
381 | * Demonstrate the use of a collection builder to chain multiple tasks |
||
382 | * together into a collection, which is executed once constructed. |
||
383 | * |
||
384 | * For demonstration purposes only; this could, of course, be done |
||
385 | * with a single FilesystemStack. |
||
386 | */ |
||
387 | public function tryBuilder() |
||
401 | |||
402 | public function tryState() |
||
412 | |||
413 | public function tryBuilderRollback() |
||
440 | |||
441 | public function tryWorkdir() |
||
468 | |||
469 | /** |
||
470 | * Demonstrates Robo temporary directory usage. |
||
471 | */ |
||
472 | public function tryTmpDir() |
||
494 | |||
495 | /** |
||
496 | * Description |
||
497 | * @param $options |
||
498 | * @option delay Miliseconds delay |
||
499 | * @return type |
||
500 | */ |
||
501 | public function tryProgress($options = ['delay' => 500]) |
||
521 | |||
522 | public function tryIter() |
||
542 | } |
||
543 | |||
558 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.