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 | class ClassMetadata |
||
| 10 | { |
||
| 11 | /** |
||
| 12 | * Model name (entity class with full namespace, ie: "Foo\Entity\Article"). |
||
| 13 | * |
||
| 14 | * @var string |
||
| 15 | * @access private |
||
| 16 | */ |
||
| 17 | private $modelName; |
||
| 18 | |||
| 19 | /** |
||
| 20 | * Model key, used as path prefix for API calls. |
||
| 21 | * |
||
| 22 | * @var string |
||
| 23 | * @access private |
||
| 24 | */ |
||
| 25 | private $key; |
||
| 26 | |||
| 27 | /** |
||
| 28 | * Repository name (repository class with full namespace, ie: "Foo\Repository\ArticleRepository"). |
||
| 29 | * |
||
| 30 | * @var string |
||
| 31 | * @access private |
||
| 32 | */ |
||
| 33 | private $repositoryName; |
||
| 34 | |||
| 35 | /** |
||
| 36 | * attributeList |
||
| 37 | * |
||
| 38 | * @var Attribute[] |
||
| 39 | * @access private |
||
| 40 | */ |
||
| 41 | private $attributeList; |
||
| 42 | |||
| 43 | /** |
||
| 44 | * relationList |
||
| 45 | * |
||
| 46 | * @var Relation[] |
||
| 47 | * @access private |
||
| 48 | */ |
||
| 49 | private $relationList; |
||
| 50 | |||
| 51 | /** |
||
| 52 | * identifierAttribute |
||
| 53 | * |
||
| 54 | * @var Attribute |
||
| 55 | * @access private |
||
| 56 | */ |
||
| 57 | private $identifierAttribute; |
||
| 58 | |||
| 59 | /** |
||
| 60 | * Constructor. |
||
| 61 | * |
||
| 62 | * @param string $key |
||
| 63 | * @param string $modelName |
||
| 64 | * @param string $repositoryName |
||
| 65 | * @access public |
||
| 66 | */ |
||
| 67 | public function __construct($key, $modelName, $repositoryName) |
||
| 73 | |||
| 74 | /** |
||
| 75 | * Getter for modelName |
||
| 76 | * |
||
| 77 | * @return string |
||
| 78 | */ |
||
| 79 | public function getModelName() |
||
| 83 | |||
| 84 | /** |
||
| 85 | * Setter for modelName |
||
| 86 | * |
||
| 87 | * @param string $modelName |
||
| 88 | * @return ClassMetadata |
||
| 89 | */ |
||
| 90 | public function setModelName($modelName) |
||
| 95 | |||
| 96 | /** |
||
| 97 | * Getter for key |
||
| 98 | * |
||
| 99 | * @return string |
||
| 100 | */ |
||
| 101 | public function getKey() |
||
| 105 | |||
| 106 | /** |
||
| 107 | * Setter for key |
||
| 108 | * |
||
| 109 | * @param string $key |
||
| 110 | * @return ClassMetadata |
||
| 111 | */ |
||
| 112 | public function setKey($key) |
||
| 118 | |||
| 119 | /** |
||
| 120 | * getAttribute |
||
| 121 | * |
||
| 122 | * @param string $name |
||
| 123 | * @access public |
||
| 124 | * @return Attribute |
||
| 125 | */ |
||
| 126 | public function getAttribute($name) |
||
| 130 | |||
| 131 | /** |
||
| 132 | * getIdentifierAttribute |
||
| 133 | * |
||
| 134 | * @access public |
||
| 135 | * @return Attribute |
||
| 136 | */ |
||
| 137 | public function getIdentifierAttribute() |
||
| 141 | |||
| 142 | /** |
||
| 143 | * Getter for attributeList |
||
| 144 | * |
||
| 145 | * @return Attribute[] |
||
| 146 | */ |
||
| 147 | public function getAttributeList() |
||
| 151 | |||
| 152 | /** |
||
| 153 | * Setter for attributeList |
||
| 154 | * |
||
| 155 | * @param Attribute[] $attributeList |
||
| 156 | * @return ClassMetadata |
||
| 157 | */ |
||
| 158 | public function setAttributeList($attributeList) |
||
| 170 | |||
| 171 | /** |
||
| 172 | * Getter for relationList |
||
| 173 | * |
||
| 174 | * @return Relation[] |
||
| 175 | */ |
||
| 176 | public function getRelationList() |
||
| 180 | |||
| 181 | /** |
||
| 182 | * Setter for relationList |
||
| 183 | * |
||
| 184 | * @param Relation[] $relationList |
||
| 185 | * @return ClassMetadata |
||
| 186 | */ |
||
| 187 | public function setRelationList($relationList) |
||
| 192 | |||
| 193 | /** |
||
| 194 | * getRelation |
||
| 195 | * |
||
| 196 | * @param string $key |
||
| 197 | * @access public |
||
| 198 | * @return Relation|null |
||
| 199 | */ |
||
| 200 | public function getRelation($key) |
||
| 210 | |||
| 211 | /** |
||
| 212 | * Getter for repositoryName |
||
| 213 | * |
||
| 214 | * @return string |
||
| 215 | */ |
||
| 216 | public function getRepositoryName() |
||
| 220 | |||
| 221 | /** |
||
| 222 | * Setter for repositoryName |
||
| 223 | * |
||
| 224 | * @param string $repositoryName |
||
| 225 | * @return ClassMetadata |
||
| 226 | */ |
||
| 227 | public function setRepositoryName($repositoryName) |
||
| 232 | |||
| 233 | View Code Duplication | private function getClassMetadata() |
|
| 243 | |||
| 244 | public function getIdGetter() |
||
| 248 | |||
| 249 | public function getIdKey() |
||
| 259 | |||
| 260 | public function getIdSerializeKey() |
||
| 270 | } |
||
| 271 |