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 Package extends Model |
||
| 25 | { |
||
| 26 | /** |
||
| 27 | * @var string CRC32 temporary uniq id of the package |
||
| 28 | */ |
||
| 29 | private $_id; |
||
| 30 | |||
| 31 | /** @var Tariff */ |
||
| 32 | protected $_tariff; |
||
| 33 | |||
| 34 | /** @var Part[] */ |
||
| 35 | public $parts = []; |
||
| 36 | |||
| 37 | /** @var array */ |
||
| 38 | public $calculation; |
||
| 39 | |||
| 40 | /** |
||
| 41 | * @var |
||
| 42 | */ |
||
| 43 | protected $_resources; |
||
| 44 | |||
| 45 | public function init() |
||
| 55 | |||
| 56 | /** |
||
| 57 | * @param Tariff $tariff |
||
| 58 | */ |
||
| 59 | public function setTariff($tariff) |
||
| 63 | |||
| 64 | /** |
||
| 65 | * @throws InvalidConfigException |
||
| 66 | * TODO: implement and get rid of many magic functions bellow |
||
| 67 | */ |
||
| 68 | protected function initResources() |
||
| 79 | |||
| 80 | /** |
||
| 81 | * @param $resource |
||
| 82 | * @return string |
||
| 83 | * TODO: implement and get rid of many magic functions bellow |
||
| 84 | */ |
||
| 85 | protected function buildResourceClass($resource) |
||
| 93 | |||
| 94 | /** |
||
| 95 | * @return Tariff |
||
| 96 | */ |
||
| 97 | public function getTariff() |
||
| 101 | |||
| 102 | protected function getResourceValue_panel() |
||
| 111 | |||
| 112 | protected function getResourceTitle_panel() |
||
| 116 | |||
| 117 | protected function getResourceValue_purpose() |
||
| 121 | |||
| 122 | protected function getResourceTitle_purpose() |
||
| 126 | |||
| 127 | /** |
||
| 128 | * @return float |
||
| 129 | */ |
||
| 130 | public function getPrice() |
||
| 134 | |||
| 135 | /** |
||
| 136 | * @throws InvalidConfigException |
||
| 137 | * @return string |
||
| 138 | */ |
||
| 139 | public function getDisplayPrice() |
||
| 145 | |||
| 146 | /** |
||
| 147 | * @return string |
||
| 148 | */ |
||
| 149 | public function getName() |
||
| 153 | |||
| 154 | /** |
||
| 155 | * @param string $type |
||
| 156 | * @throws InvalidConfigException |
||
| 157 | * @return mixed |
||
| 158 | */ |
||
| 159 | View Code Duplication | public function getResourceValue($type) |
|
| 169 | |||
| 170 | /** |
||
| 171 | * @param string $type |
||
| 172 | * @throws InvalidConfigException |
||
| 173 | * @return string |
||
| 174 | */ |
||
| 175 | View Code Duplication | public function getResourceTitle($type) |
|
| 184 | |||
| 185 | /** |
||
| 186 | * @param $type |
||
| 187 | * @throws InvalidConfigException |
||
| 188 | * @return array|null |
||
| 189 | */ |
||
| 190 | View Code Duplication | public function getOverusePrice($type) |
|
| 199 | |||
| 200 | /** |
||
| 201 | * @param string $type |
||
| 202 | * @return Part|null |
||
| 203 | */ |
||
| 204 | public function getPartByType($type) |
||
| 214 | |||
| 215 | /** |
||
| 216 | * @param string $type |
||
| 217 | * @return Resource|null |
||
| 218 | */ |
||
| 219 | public function getResourceByType($type) |
||
| 229 | |||
| 230 | /** |
||
| 231 | * @param string $type |
||
| 232 | * @return resource|null |
||
| 233 | */ |
||
| 234 | public function getResourceByModelType($type) |
||
| 244 | |||
| 245 | /** |
||
| 246 | * @return array |
||
| 247 | */ |
||
| 248 | public function getLocations() |
||
| 254 | |||
| 255 | /** |
||
| 256 | * @return string |
||
| 257 | */ |
||
| 258 | public function getId() |
||
| 266 | } |
||
| 267 |
Since your code implements the magic getter
_get, this function will be called for any read access on an undefined variable. You can add the@propertyannotation to your class or interface to document the existence of this variable.If the property has read access only, you can use the @property-read 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.