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 |
||
| 9 | View Code Duplication | class UrlOptionsBuilder extends AbstractOptionsBuilder |
|
|
|
|||
| 10 | { |
||
| 11 | use OptionAccessorsTrait; |
||
| 12 | use Behavior\AttrPlaceHolderTrait; |
||
| 13 | use Behavior\AutofocusTrait; |
||
| 14 | use Behavior\AutocompleteTrait; |
||
| 15 | |||
| 16 | const PROTOCOL_HTTP = 'http'; |
||
| 17 | const PROTOCOL_HTTPS = 'https'; |
||
| 18 | const PROTOCOL_FTP = 'ftp'; |
||
| 19 | |||
| 20 | /** |
||
| 21 | * @return string |
||
| 22 | */ |
||
| 23 | public static function getBuilderType() |
||
| 27 | |||
| 28 | /** |
||
| 29 | * @param mixed $protocol |
||
| 30 | * @return $this |
||
| 31 | * @link http://symfony.com/doc/current/reference/forms/types/url.html#default-protocol |
||
| 32 | */ |
||
| 33 | public function setDefaultProtocol($protocol) |
||
| 37 | |||
| 38 | /** |
||
| 39 | * @return mixed |
||
| 40 | */ |
||
| 41 | public function getDefaultProtocol() |
||
| 45 | } |
||
| 46 |
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.