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 |
||
17 | abstract class BaseRepository extends \yii\base\Component |
||
18 | { |
||
19 | /** |
||
20 | * @var ConnectionInterface |
||
21 | */ |
||
22 | protected $db; |
||
23 | |||
24 | protected $factory; |
||
25 | |||
26 | /** |
||
27 | * @var string |
||
28 | */ |
||
29 | public $queryClass; |
||
30 | |||
31 | public function find(ActiveQuery $query) |
||
37 | |||
38 | public function setRecordClass($value) |
||
42 | |||
43 | public function getRecordClass() |
||
51 | |||
52 | public function findRecordClass() |
||
58 | |||
59 | View Code Duplication | public function findAll(Specification $specification) |
|
69 | |||
70 | public function findOne(Specification $specification) |
||
76 | |||
77 | View Code Duplication | public function old_findOne(Specification $specification) |
|
86 | |||
87 | protected function buildSelectQuery(Specification $specification) |
||
91 | |||
92 | protected function buildQuery() |
||
96 | |||
97 | protected function getQueryClass() |
||
101 | |||
102 | protected function createMultiple($rows) |
||
111 | |||
112 | protected function create(array $row) |
||
116 | |||
117 | protected function createDto(array $row) |
||
131 | |||
132 | protected function getEntityCreationDtoClass() |
||
140 | |||
141 | public function createEntity($entityClass, $row) |
||
145 | } |
||
146 |
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.