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 |
||
17 | class CreateDataObjectCommand extends Command |
||
18 | { |
||
19 | const ARGUMENTS_NAME = 'name'; |
||
20 | const ARGUMENTS_NAMESPACE = 'namespace'; |
||
21 | const ARGUMENTS_PATH = 'path'; |
||
22 | const OPTIONS_HAS_ONE = 'withHasOne'; |
||
23 | const OPTIONS_HAS_MANY = 'withHasMany'; |
||
24 | const OPTIONS_MANY_MANY = 'withManyMany'; |
||
25 | const OPTIONS_TRADITIONAL_ARRAY = 'withTraditionalArray'; |
||
26 | |||
27 | /** |
||
28 | * @var string |
||
29 | */ |
||
30 | private $name; |
||
|
|||
31 | |||
32 | /** |
||
33 | * @var string |
||
34 | */ |
||
35 | private $namespace; |
||
36 | |||
37 | /** |
||
38 | * @var string |
||
39 | */ |
||
40 | private $modulePath; |
||
41 | |||
42 | /** |
||
43 | * @var Filesystem |
||
44 | */ |
||
45 | private $fileSystem; |
||
46 | |||
47 | /** |
||
48 | * @var string The target frameowkr version |
||
49 | */ |
||
50 | private $frameworkVersion = 'ss4'; |
||
51 | |||
52 | /** |
||
53 | * @var string |
||
54 | */ |
||
55 | private $separator = DIRECTORY_SEPARATOR; |
||
56 | |||
57 | /** |
||
58 | * Whether or not to use traditional array syntax |
||
59 | * @var bool |
||
60 | */ |
||
61 | private $useTraditionalArraySyntax = false; |
||
62 | |||
63 | /** |
||
64 | * Configures the command |
||
65 | */ |
||
66 | View Code Duplication | protected function configure() |
|
79 | |||
80 | /** |
||
81 | * Executes this command |
||
82 | * @param InputInterface $input |
||
83 | * @param OutputInterface $output |
||
84 | * @return int|null|void |
||
85 | */ |
||
86 | protected function execute(InputInterface $input, OutputInterface $output) |
||
100 | |||
101 | /** |
||
102 | * Sets the argument values to their respective properties |
||
103 | * @param InputInterface $input |
||
104 | * @throws RuntimeException |
||
105 | */ |
||
106 | View Code Duplication | protected function setArguments(InputInterface $input) |
|
115 | |||
116 | /** |
||
117 | * @param InputInterface $input |
||
118 | */ |
||
119 | protected function preCopyOptions(InputInterface $input) |
||
125 | |||
126 | /** |
||
127 | * Checks for and actions all actions |
||
128 | * @param InputInterface $input |
||
129 | * @param OutputInterface $output |
||
130 | */ |
||
131 | protected function postCopyOptions(InputInterface $input) |
||
162 | |||
163 | /** |
||
164 | * Copies the skeleton to the root directory |
||
165 | */ |
||
166 | protected function copySkeleton() |
||
173 | |||
174 | /** |
||
175 | * Copies the configured values to the composer.json file |
||
176 | */ |
||
177 | protected function setupComposerJson() |
||
195 | |||
196 | /** |
||
197 | * Gets or sets the file system property |
||
198 | * @return Filesystem |
||
199 | */ |
||
200 | protected function getFilesystem() |
||
208 | |||
209 | /** |
||
210 | * Returns the path to the given sub-dir. Defaults to assets skeleton |
||
211 | * @param string $subDir |
||
212 | * @return string |
||
213 | */ |
||
214 | protected function getSourcePath($subDir = 'assets') |
||
219 | |||
220 | /** |
||
221 | * Gets destination path for the module skeleton |
||
222 | * @return string |
||
223 | */ |
||
224 | protected function getTargetPath() |
||
229 | |||
230 | /** |
||
231 | * @return bool |
||
232 | */ |
||
233 | public function isTraditionalSyntax() |
||
237 | |||
238 | /** |
||
239 | * @param bool $traditionalSyntax |
||
240 | * @return CreateDataObjectCommand |
||
241 | */ |
||
242 | public function setTraditionalSyntax($traditionalSyntax) |
||
247 | } |
||
248 |