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 |
||
21 | class Calculation extends \hipanel\base\Model |
||
22 | { |
||
23 | use \hipanel\base\ModelTrait; |
||
24 | |||
25 | /** {@inheritdoc} */ |
||
26 | public static function index() |
||
30 | |||
31 | /** {@inheritdoc} */ |
||
32 | public static function type() |
||
36 | |||
37 | /** {@inheritdoc} */ |
||
38 | public static function primaryKey() |
||
42 | |||
43 | /** {@inheritdoc} */ |
||
44 | public function init() |
||
54 | |||
55 | public function getValue() |
||
59 | |||
60 | public function forCurrency($currency) |
||
68 | |||
69 | /** {@inheritdoc} */ |
||
70 | View Code Duplication | public function rules() |
|
77 | |||
78 | /** |
||
79 | * Synchronises the model to represent actual state of [[position]] |
||
80 | * The method must update values, that affects the calculation and |
||
81 | * can be changed in cart without position re-adding. |
||
82 | * For example: quantity. |
||
83 | */ |
||
84 | public function synchronize() |
||
88 | } |
||
89 |
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@property
annotation 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.