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 |
||
19 | abstract class AbstractCommand extends Command implements ContainerAwareInterface |
||
20 | { |
||
21 | /** |
||
22 | * @var SymfonyStyle |
||
23 | */ |
||
24 | protected $io; |
||
25 | |||
26 | /** |
||
27 | * @var boolean |
||
28 | */ |
||
29 | protected $debug = false; |
||
30 | |||
31 | /** |
||
32 | * @var ContainerInterface |
||
33 | */ |
||
34 | protected $container; |
||
35 | |||
36 | /** |
||
37 | * @var EventDispatcherInterface |
||
38 | */ |
||
39 | protected $eventDispatcher; |
||
40 | |||
41 | /** |
||
42 | * Build tasks from the configuration array. |
||
43 | * |
||
44 | * @param array $configuration |
||
45 | * |
||
46 | * @return Task[] |
||
47 | */ |
||
48 | 1 | View Code Duplication | protected function buildTasks(array $configuration) |
60 | |||
61 | /** |
||
62 | * Build the filter according to the configuration array. |
||
63 | * |
||
64 | * @param array $configuration |
||
65 | * |
||
66 | * @return FilterInterface[] |
||
67 | */ |
||
68 | 1 | View Code Duplication | protected function buildFilters(array $configuration) |
80 | |||
81 | /** |
||
82 | * Load the configuration from a yml file. |
||
83 | * |
||
84 | * @param $configurationFile |
||
85 | * |
||
86 | * @return string[] |
||
87 | * |
||
88 | * @throws Exception |
||
89 | */ |
||
90 | protected function loadConfigurationFile($configurationFile) |
||
103 | |||
104 | /** |
||
105 | * Load the configuration from a yml file or the container, according to the given option. |
||
106 | * |
||
107 | * @param InputInterface $input |
||
108 | * |
||
109 | * @return array |
||
110 | * |
||
111 | * @throws Exception |
||
112 | */ |
||
113 | 1 | protected function loadConfiguration(InputInterface $input) |
|
129 | |||
130 | /** |
||
131 | * Sets the container. |
||
132 | * |
||
133 | * @param ContainerInterface|null $container A ContainerInterface instance or null |
||
134 | */ |
||
135 | 1 | public function setContainer(ContainerInterface $container = null) |
|
140 | } |
||
141 |