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 |
||
| 24 | class Content extends APIContent |
||
| 25 | { |
||
| 26 | /** |
||
| 27 | * @var mixed[][] An array of array of field values like[$fieldDefIdentifier][$languageCode] |
||
| 28 | */ |
||
| 29 | protected $fields; |
||
| 30 | |||
| 31 | /** |
||
| 32 | * @var \eZ\Publish\API\Repository\Values\Content\VersionInfo |
||
| 33 | */ |
||
| 34 | protected $versionInfo; |
||
| 35 | |||
| 36 | /** |
||
| 37 | * @var \eZ\Publish\API\Repository\Values\Content\Field[] An array of {@link Field} |
||
| 38 | */ |
||
| 39 | private $internalFields = array(); |
||
| 40 | |||
| 41 | /** |
||
| 42 | * The first matched field language among user provided prioritized languages. |
||
| 43 | * |
||
| 44 | * The first matched language among user provided prioritized languages on object retrieval, or null if none |
||
| 45 | * provided (all languages) or on main fallback. |
||
| 46 | * |
||
| 47 | * @internal |
||
| 48 | * @var string|null |
||
| 49 | */ |
||
| 50 | protected $prioritizedFieldLanguageCode; |
||
| 51 | |||
| 52 | public function __construct(array $data = array()) |
||
| 58 | |||
| 59 | private function populateFields() |
||
| 69 | |||
| 70 | /** |
||
| 71 | * {@inheritdoc} |
||
| 72 | */ |
||
| 73 | public function getVersionInfo() |
||
| 77 | |||
| 78 | /** |
||
| 79 | * {@inheritdoc} |
||
| 80 | */ |
||
| 81 | public function getFieldValue($fieldDefIdentifier, $languageCode = null) |
||
| 94 | |||
| 95 | /** |
||
| 96 | * {@inheritdoc} |
||
| 97 | */ |
||
| 98 | public function getFields() |
||
| 102 | |||
| 103 | /** |
||
| 104 | * {@inheritdoc} |
||
| 105 | */ |
||
| 106 | View Code Duplication | public function getFieldsByLanguage($languageCode = null) |
|
| 123 | |||
| 124 | /** |
||
| 125 | * {@inheritdoc} |
||
| 126 | */ |
||
| 127 | public function getField($fieldDefIdentifier, $languageCode = null) |
||
| 142 | |||
| 143 | /** |
||
| 144 | * {@inheritdoc} |
||
| 145 | */ |
||
| 146 | protected function getProperties($dynamicProperties = array('id', 'contentInfo')) |
||
| 150 | |||
| 151 | /** |
||
| 152 | * {@inheritdoc} |
||
| 153 | */ |
||
| 154 | public function __get($property) |
||
| 169 | |||
| 170 | /** |
||
| 171 | * {@inheritdoc} |
||
| 172 | */ |
||
| 173 | public function __isset($property) |
||
| 185 | } |
||
| 186 |
Since your code implements the magic setter
_set, this function will be called for any write access on an undefined variable. You can add the@propertyannotation to your class or interface to document the existence of this variable.Since the property has write access only, you can use the @property-write annotation instead.
Of course, you may also just have mistyped another name, in which case you should fix the error.
See also the PhpDoc documentation for @property.