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 |
||
| 18 | class User extends APIUser |
||
| 19 | { |
||
| 20 | /** |
||
| 21 | * @var int MD5 of password, not recommended |
||
| 22 | */ |
||
| 23 | const PASSWORD_HASH_MD5_PASSWORD = 1; |
||
| 24 | |||
| 25 | /** |
||
| 26 | * @var int MD5 of user and password |
||
| 27 | */ |
||
| 28 | const PASSWORD_HASH_MD5_USER = 2; |
||
| 29 | |||
| 30 | /** |
||
| 31 | * @var int MD5 of site, user and password |
||
| 32 | */ |
||
| 33 | const PASSWORD_HASH_MD5_SITE = 3; |
||
| 34 | |||
| 35 | /** |
||
| 36 | * @var int Passwords in plaintext, should not be used for real sites |
||
| 37 | */ |
||
| 38 | const PASSWORD_HASH_PLAINTEXT = 5; |
||
| 39 | |||
| 40 | /** |
||
| 41 | * Internal content representation. |
||
| 42 | * |
||
| 43 | * @var \eZ\Publish\API\Repository\Values\Content\Content |
||
| 44 | */ |
||
| 45 | protected $content; |
||
| 46 | |||
| 47 | /** |
||
| 48 | * Returns the VersionInfo for this version. |
||
| 49 | * |
||
| 50 | * @return \eZ\Publish\API\Repository\Values\Content\VersionInfo |
||
| 51 | */ |
||
| 52 | public function getVersionInfo() |
||
| 56 | |||
| 57 | /** |
||
| 58 | * Returns a field value for the given value |
||
| 59 | * $version->fields[$fieldDefId][$languageCode] is an equivalent call |
||
| 60 | * if no language is given on a translatable field this method returns |
||
| 61 | * the value of the initial language of the version if present, otherwise null. |
||
| 62 | * On non translatable fields this method ignores the languageCode parameter. |
||
| 63 | * |
||
| 64 | * @param string $fieldDefIdentifier |
||
| 65 | * @param string $languageCode |
||
| 66 | * |
||
| 67 | * @return mixed a primitive type or a field type Value object depending on the field type. |
||
| 68 | */ |
||
| 69 | public function getFieldValue($fieldDefIdentifier, $languageCode = null) |
||
| 73 | |||
| 74 | /** |
||
| 75 | * This method returns the complete fields collection. |
||
| 76 | * |
||
| 77 | * @return \eZ\Publish\API\Repository\Values\Content\Field[] |
||
| 78 | */ |
||
| 79 | public function getFields() |
||
| 83 | |||
| 84 | /** |
||
| 85 | * This method returns the fields for a given language and non translatable fields. |
||
| 86 | * |
||
| 87 | * If note set the initialLanguage of the content version is used. |
||
| 88 | * |
||
| 89 | * @param string $languageCode |
||
| 90 | * |
||
| 91 | * @return \eZ\Publish\API\Repository\Values\Content\Field[] with field identifier as keys |
||
| 92 | */ |
||
| 93 | public function getFieldsByLanguage($languageCode = null) |
||
| 97 | |||
| 98 | /** |
||
| 99 | * This method returns the field for a given field definition identifier and language. |
||
| 100 | * |
||
| 101 | * If not set the initialLanguage of the content version is used. |
||
| 102 | * |
||
| 103 | * @param string $fieldDefIdentifier |
||
| 104 | * @param string|null $languageCode |
||
| 105 | * |
||
| 106 | * @return \eZ\Publish\API\Repository\Values\Content\Field|null A {@link Field} or null if nothing is found |
||
| 107 | */ |
||
| 108 | public function getField($fieldDefIdentifier, $languageCode = null) |
||
| 109 | { |
||
| 110 | return $this->content->getField($fieldDefIdentifier, $languageCode); |
||
| 111 | } |
||
| 112 | |||
| 113 | /** |
||
| 114 | * Function where list of properties are returned. |
||
| 115 | * |
||
| 116 | * Override to add dynamic properties |
||
| 117 | * |
||
| 118 | * @uses \parent::getProperties() |
||
| 119 | * |
||
| 120 | * @param array $dynamicProperties |
||
| 121 | * |
||
| 122 | * @return array |
||
| 123 | */ |
||
| 124 | protected function getProperties($dynamicProperties = array('id', 'contentInfo')) |
||
| 128 | |||
| 129 | /** |
||
| 130 | * Magic getter for retrieving convenience properties. |
||
| 131 | * |
||
| 132 | * @param string $property The name of the property to retrieve |
||
| 133 | * |
||
| 134 | * @return mixed |
||
| 135 | */ |
||
| 136 | View Code Duplication | public function __get($property) |
|
| 159 | |||
| 160 | /** |
||
| 161 | * Magic isset for signaling existence of convenience properties. |
||
| 162 | * |
||
| 163 | * @param string $property |
||
| 164 | * |
||
| 165 | * @return bool |
||
| 166 | */ |
||
| 167 | View Code Duplication | public function __isset($property) |
|
| 187 | } |
||
| 188 |