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 |
||
| 7 | class RepositoryEloquentGenerator extends Generator |
||
| 8 | { |
||
| 9 | /** |
||
| 10 | * Get stub name. |
||
| 11 | * |
||
| 12 | * @var string |
||
| 13 | */ |
||
| 14 | protected $stub = 'repository/eloquent'; |
||
| 15 | |||
| 16 | /** |
||
| 17 | * Get root namespace. |
||
| 18 | * |
||
| 19 | * @return string |
||
| 20 | */ |
||
| 21 | public function getRootNamespace() |
||
| 25 | |||
| 26 | /** |
||
| 27 | * Get generator path config node. |
||
| 28 | * |
||
| 29 | * @return string |
||
| 30 | */ |
||
| 31 | public function getPathConfigNode() |
||
| 35 | |||
| 36 | /** |
||
| 37 | * Get destination path for generated file. |
||
| 38 | * |
||
| 39 | * @return string |
||
| 40 | */ |
||
| 41 | public function getPath() |
||
| 46 | |||
| 47 | /** |
||
| 48 | * Get base path of destination file. |
||
| 49 | * |
||
| 50 | * @return string |
||
| 51 | */ |
||
| 52 | public function getBasePath() |
||
| 56 | |||
| 57 | /** |
||
| 58 | * Get array replacements. |
||
| 59 | * |
||
| 60 | * @return array |
||
| 61 | */ |
||
| 62 | public function getReplacements() |
||
| 81 | |||
| 82 | /** |
||
| 83 | * Get the fillable attributes. |
||
| 84 | * |
||
| 85 | * @return string |
||
| 86 | */ |
||
| 87 | public function getFillable() |
||
| 100 | |||
| 101 | /** |
||
| 102 | * Get schema parser. |
||
| 103 | * |
||
| 104 | * @return SchemaParser |
||
| 105 | */ |
||
| 106 | public function getSchemaParser() |
||
| 110 | |||
| 111 | /** |
||
| 112 | * @return string |
||
| 113 | */ |
||
| 114 | public function getValidatorUse() |
||
| 120 | |||
| 121 | /** |
||
| 122 | * @return string |
||
| 123 | */ |
||
| 124 | View Code Duplication | public function getValidator() |
|
| 139 | |||
| 140 | /** |
||
| 141 | * @return string |
||
| 142 | */ |
||
| 143 | View Code Duplication | public function getValidatorMethod() |
|
| 153 | |||
| 154 | /** |
||
| 155 | * @return string |
||
| 156 | */ |
||
| 157 | public function getPresenterUse() |
||
| 163 | |||
| 164 | /** |
||
| 165 | * @return string |
||
| 166 | */ |
||
| 167 | View Code Duplication | public function getPresenter() |
|
| 181 | |||
| 182 | /** |
||
| 183 | * @return string |
||
| 184 | */ |
||
| 185 | View Code Duplication | public function getPresenterMethod() |
|
| 194 | |||
| 195 | /** |
||
| 196 | * @return string |
||
| 197 | */ |
||
| 198 | View Code Duplication | public function getCriteria() |
|
| 212 | } |
||
| 213 |
This check looks for a call to a parent method whose name is different than the method from which it is called.
Consider the following code:
The
getFirstName()method in theSoncalls the wrong method in the parent class.