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 ShowOnlyFor 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 | 5 | protected function applyModification() { |
|
| 47 | 5 | if ( ! $this->isShown() ) { |
|
| 48 | 5 | $c = $this->getComponent(); |
|
| 49 | 5 | $this->setComponent( new Silent( $c->getSkinTemplate(), $c->getDomElement(), $c->getIndent() ) ); |
|
| 50 | 5 | } |
|
| 51 | 5 | } |
|
| 52 | |||
| 53 | /** |
||
| 54 | * @return bool |
||
| 55 | */ |
||
| 56 | 5 | private function isShown() { |
|
| 60 | |||
| 61 | /** |
||
| 62 | * @return PermissionsHelper |
||
| 63 | */ |
||
| 64 | 5 | private function getPermissionsHelper() { |
|
| 71 | } |