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 |
||
38 | abstract class AbstractReadCommand extends Command |
||
39 | { |
||
40 | |||
41 | /** |
||
42 | * Constant for the "today" keyword |
||
43 | * |
||
44 | * @var string FILTER_KEYWORD_TODAY |
||
45 | */ |
||
46 | const FILTER_KEYWORD_TODAY = 'today'; |
||
47 | |||
48 | /** |
||
49 | * Constant for the "yesterday" keyword |
||
50 | * |
||
51 | * @var string FILTER_KEYWORD_YESTERDAY |
||
52 | */ |
||
53 | const FILTER_KEYWORD_YESTERDAY = 'yesterday'; |
||
54 | |||
55 | /** |
||
56 | * Constant for the "current" keyword |
||
57 | * |
||
58 | * @var string FILTER_KEYWORD_CURRENT |
||
59 | */ |
||
60 | const FILTER_KEYWORD_CURRENT = 'current'; |
||
61 | |||
62 | /** |
||
63 | * Constant for the "to" option |
||
64 | * |
||
65 | * @var string OPTION_TO |
||
66 | */ |
||
67 | const OPTION_TO = 'to'; |
||
68 | |||
69 | /** |
||
70 | * Constant for the "from" option |
||
71 | * |
||
72 | * @var string OPTION_FROM |
||
73 | */ |
||
74 | const OPTION_FROM = 'from'; |
||
75 | |||
76 | /** |
||
77 | * Configures the "show" command |
||
78 | * |
||
79 | * @return void |
||
80 | * |
||
81 | * {@inheritDoc} |
||
82 | * @see \Symfony\Component\Console\Command\Command::configure() |
||
83 | */ |
||
84 | protected function configure() |
||
105 | |||
106 | /** |
||
107 | * @param InputInterface $input |
||
108 | * @param $ticket |
||
109 | * @param $toDate |
||
110 | * @param $fromDate |
||
111 | * @param $limit |
||
112 | */ |
||
113 | protected function prepareInputParams(InputInterface $input, & $ticket, & $fromDate, & $toDate, & $limit) |
||
152 | } |
||
153 |
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.