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 /** MicroHtml5TagTrait */ |
||
| 18 | trait Html5TagTrait |
||
| 19 | { |
||
| 20 | use TagTrait; |
||
| 21 | |||
| 22 | |||
| 23 | /** |
||
| 24 | * Render charset tag |
||
| 25 | * |
||
| 26 | * @access public |
||
| 27 | * |
||
| 28 | * @param string $name charset name |
||
| 29 | * |
||
| 30 | * @return string |
||
| 31 | * @static |
||
| 32 | */ |
||
| 33 | public static function charset($name) |
||
| 37 | |||
| 38 | /** |
||
| 39 | * Render video tag |
||
| 40 | * |
||
| 41 | * @access public |
||
| 42 | * |
||
| 43 | * @param array $sources format type=>src |
||
| 44 | * @param array $videos format array(kind, src, srclang, label) |
||
| 45 | * @param array $attributes attributes tag |
||
| 46 | * @param string $noCodec text |
||
| 47 | * |
||
| 48 | * @return string |
||
| 49 | * @static |
||
| 50 | */ |
||
| 51 | View Code Duplication | public static function video(array $sources = [], array $videos = [], array $attributes = [], $noCodec = '') |
|
| 70 | |||
| 71 | /** |
||
| 72 | * Render audio tag |
||
| 73 | * |
||
| 74 | * @access public |
||
| 75 | * |
||
| 76 | * @param array $sources format type=>src |
||
| 77 | * @param array $tracks format array(kind, src, srclang, label) |
||
| 78 | * @param array $attributes attributes tag |
||
| 79 | * @param string $noCodec text |
||
| 80 | * |
||
| 81 | * @return string |
||
| 82 | * @static |
||
| 83 | */ |
||
| 84 | View Code Duplication | public static function audio(array $sources = [], array $tracks = [], array $attributes = [], $noCodec = '') |
|
| 103 | |||
| 104 | /** |
||
| 105 | * Render canvas tag |
||
| 106 | * |
||
| 107 | * @access public |
||
| 108 | * |
||
| 109 | * @param array $attributes attributes tag |
||
| 110 | * @param string $noCodec text |
||
| 111 | * |
||
| 112 | * @return string |
||
| 113 | * @static |
||
| 114 | */ |
||
| 115 | public static function canvas(array $attributes = [], $noCodec = '') |
||
| 119 | } |
||
| 120 |
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.