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 |
||
21 | View Code Duplication | class GroupKeyword extends Component |
|
|
|||
22 | { |
||
23 | /** |
||
24 | * The expression that is used for ordering. |
||
25 | * |
||
26 | * @var Expression |
||
27 | */ |
||
28 | public $expr; |
||
29 | |||
30 | /** |
||
31 | * The order type. |
||
32 | * |
||
33 | * @var string |
||
34 | */ |
||
35 | public $type; |
||
36 | |||
37 | /** |
||
38 | * Constructor. |
||
39 | * |
||
40 | * @param Expression $expr the expression that we are sorting by |
||
41 | * @param string $type the sorting type |
||
42 | */ |
||
43 | public function __construct($expr = null, $type = '') |
||
48 | |||
49 | /** |
||
50 | * @param Parser $parser the parser that serves as context |
||
51 | * @param TokensList $list the list of tokens that are being parsed |
||
52 | * @param array $options parameters for parsing |
||
53 | * |
||
54 | * @return GroupKeyword[] |
||
55 | */ |
||
56 | public static function parse(Parser $parser, TokensList $list, array $options = array()) |
||
125 | |||
126 | /** |
||
127 | * @param GroupKeyword|GroupKeyword[] $component the component to be built |
||
128 | * @param array $options parameters for building |
||
129 | * |
||
130 | * @return string |
||
131 | */ |
||
132 | public static function build($component, array $options = array()) |
||
141 | } |
||
142 |
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.