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 |
||
| 14 | abstract class Treeview extends Collection { |
||
| 15 | |||
| 16 | /** |
||
| 17 | * Get the join statement |
||
| 18 | */ |
||
| 19 | |||
| 20 | protected function getQueryJoin(int $parent_id) : string { |
||
| 28 | |||
| 29 | /** |
||
| 30 | * Get the select query |
||
| 31 | */ |
||
| 32 | |||
| 33 | private function getSelectQuery(int $parent_id, array $config, array $order_by) : string { |
||
| 45 | |||
| 46 | /** |
||
| 47 | * Get the count query |
||
| 48 | */ |
||
| 49 | |||
| 50 | private function getCountQuery(int $parent_id) : string { |
||
| 56 | |||
| 57 | /** |
||
| 58 | * Get the depth query |
||
| 59 | */ |
||
| 60 | |||
| 61 | private function getDepthQuery(int $parent_id) : string { |
||
| 71 | |||
| 72 | /** |
||
| 73 | * Get the entity subtree |
||
| 74 | * |
||
| 75 | * @param $parent_id an id of a parent entity |
||
| 76 | * @param $config an array of filtering options |
||
| 77 | * @param $order_by an array where each key is a field name and each value is a sorting direction (ASC or DESC) |
||
| 78 | * |
||
| 79 | * @return array|false : the multidimensional array containing the tree or false on failure |
||
| 80 | */ |
||
| 81 | |||
| 82 | public function getSubtree(int $parent_id = 0, array $config = [], array $order_by = []) { |
||
| 109 | |||
| 110 | /** |
||
| 111 | * Get the count of items within the entity subtree |
||
| 112 | * |
||
| 113 | * @param $parent_id : an id of a parent entity |
||
| 114 | * |
||
| 115 | * @return int|false : the number of entities or false on failure |
||
| 116 | */ |
||
| 117 | |||
| 118 | View Code Duplication | public function getSubtreeCount(int $parent_id = 0) { |
|
| 132 | |||
| 133 | /** |
||
| 134 | * Get the subtree depth |
||
| 135 | * |
||
| 136 | * @param $parent_id : an id of a parent entity |
||
| 137 | * |
||
| 138 | * @return int|false : the depth or false on failure |
||
| 139 | */ |
||
| 140 | |||
| 141 | View Code Duplication | public function getSubtreeDepth(int $parent_id = 0) { |
|
| 155 | |||
| 156 | /** |
||
| 157 | * Get the entity path |
||
| 158 | * |
||
| 159 | * @param $parent_id : an id of a parent entity |
||
| 160 | * |
||
| 161 | * @return array|false : the array of path items or false on failure |
||
| 162 | */ |
||
| 163 | |||
| 164 | public function getPath(int $parent_id = 0) { |
||
| 190 | } |
||
| 191 | } |
||
| 192 |
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.