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 | View Code Duplication | class HideFor extends Modification { |
|
39 | |||
40 | private $permissionsHelper; |
||
41 | |||
42 | /** |
||
43 | * This method checks if the restriction is applicable and if necessary |
||
44 | * replaces the decorated component by a Silent component |
||
45 | */ |
||
46 | 2 | protected function applyModification() { |
|
47 | 2 | if ( $this->isHidden() ) { |
|
48 | 2 | $c = $this->getComponent(); |
|
49 | 2 | $this->setComponent( new Silent( $c->getSkinTemplate(), $c->getDomElement(), $c->getIndent() ) ); |
|
50 | 2 | } |
|
51 | 2 | } |
|
52 | |||
53 | /** |
||
54 | * @return bool |
||
55 | */ |
||
56 | 2 | private function isHidden() { |
|
60 | |||
61 | /** |
||
62 | * @return PermissionsHelper |
||
63 | */ |
||
64 | 2 | private function getPermissionsHelper() { |
|
71 | } |