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 |
||
22 | class InitCommand extends Command |
||
23 | { |
||
24 | const COMPLETED_LOGO = ' |
||
25 | ____ |
||
26 | _.\' : `._ |
||
27 | .-.\'`. ; .\'`.-. |
||
28 | __ / : ___\ ; /___ ; \ __ |
||
29 | ,\'_ ""--.:__;".-.";: :".-.":__;.--"" _`, |
||
30 | :\' `.t""--.. \'<@.`;_ \',@>` ..--""j.\' `; |
||
31 | `:-.._J \'-.-\'L__ `-- \' L_..-;\' |
||
32 | "-.__ ; .-" "-. : __.-" |
||
33 | L \' /.------.\ \' J |
||
34 | "-. "--" .-" |
||
35 | __.l"-:_JL_;-";.__ |
||
36 | .-j/\'.; ;"""" / .\'\"-. |
||
37 | .\' /:`. "-.: .-" .\'; `. |
||
38 | .-" / ; "-. "-..-" .-" : "-. |
||
39 | .+"-. : : "-.__.-" ;-._ \ |
||
40 | ; \ `.; ; : : "+. ; |
||
41 | : ; ; ; : ; : \: |
||
42 | : `."-; ; ; : ; ,/; |
||
43 | ; -: ; : ; : .-"\' : |
||
44 | :\ \ : ; : \.-" : |
||
45 | ;`. \ ; : ;.\'_..-- / ; |
||
46 | : "-. "-: ; :/." .\' : |
||
47 | \ .-`.\ /t-"" ":-+. : |
||
48 | `. .-" `l __/ /`. : ; ; \ ; |
||
49 | \ .-" .-"-.-" .\' .\'j \ / ;/ |
||
50 | \ / .-" /. .\'.\' ;_:\' ; |
||
51 | :-""-.`./-.\' / `.___.\' |
||
52 | \ `t ._ / bug :F_P: |
||
53 | "-.t-._:\' |
||
54 | |||
55 | Installation is completed. |
||
56 | May the Force be with you. |
||
57 | '; |
||
58 | |||
59 | /** |
||
60 | * @var string Path to directory with templates of the application files. |
||
61 | */ |
||
62 | protected $tmplDir; |
||
63 | /** |
||
64 | * @var string Default name of directory with environments settings. |
||
65 | */ |
||
66 | protected $envDir = 'environments'; |
||
67 | /** |
||
68 | * @var QuestionHelper $question |
||
69 | */ |
||
70 | protected $questionHelper; |
||
71 | |||
72 | /** |
||
73 | * {@inheritdoc} |
||
74 | */ |
||
75 | protected function configure() |
||
81 | |||
82 | /** |
||
83 | * {@inheritdoc} |
||
84 | */ |
||
85 | protected function initialize(InputInterface $input, OutputInterface $output) |
||
92 | |||
93 | /** |
||
94 | * {@inheritdoc} |
||
95 | */ |
||
96 | protected function execute(InputInterface $input, OutputInterface $output) |
||
105 | |||
106 | /** |
||
107 | * Creates directory with environments settings. |
||
108 | * |
||
109 | * @param InputInterface $input |
||
110 | * @param OutputInterface $output |
||
111 | */ |
||
112 | protected function createEnvironmentsDir(InputInterface $input, OutputInterface $output) |
||
148 | |||
149 | /** |
||
150 | * Creates configuration file of application. |
||
151 | * |
||
152 | * @param InputInterface $input |
||
153 | * @param OutputInterface $output |
||
154 | */ |
||
155 | protected function createConfiguration(InputInterface $input, OutputInterface $output) |
||
208 | } |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.