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 |
||
| 19 | class GroupModel extends Model |
||
| 20 | { |
||
| 21 | /** |
||
| 22 | * SQL table name. |
||
| 23 | * |
||
| 24 | * @var string |
||
| 25 | */ |
||
| 26 | const TABLE = 'groups'; |
||
| 27 | |||
| 28 | /** |
||
| 29 | * Get query to fetch all groups. |
||
| 30 | * |
||
| 31 | * @return \PicoDb\Table |
||
| 32 | */ |
||
| 33 | public function getQuery() |
||
| 37 | |||
| 38 | /** |
||
| 39 | * Get a specific group by id. |
||
| 40 | * |
||
| 41 | * @param int $group_id |
||
| 42 | * |
||
| 43 | * @return array |
||
| 44 | */ |
||
| 45 | public function getById($group_id) |
||
| 49 | |||
| 50 | /** |
||
| 51 | * Get a specific group by external id. |
||
| 52 | * |
||
| 53 | * @param int $external_id |
||
| 54 | * |
||
| 55 | * @return array |
||
| 56 | */ |
||
| 57 | public function getByExternalId($external_id) |
||
| 61 | |||
| 62 | /** |
||
| 63 | * Get all groups. |
||
| 64 | * |
||
| 65 | * @return array |
||
| 66 | */ |
||
| 67 | public function getAll() |
||
| 71 | |||
| 72 | /** |
||
| 73 | * Search groups by name. |
||
| 74 | * |
||
| 75 | * @param string $input |
||
| 76 | * |
||
| 77 | * @return array |
||
| 78 | */ |
||
| 79 | public function search($input) |
||
| 83 | |||
| 84 | /** |
||
| 85 | * Remove a group. |
||
| 86 | * |
||
| 87 | * @param int $group_id |
||
| 88 | * |
||
| 89 | * @return bool |
||
| 90 | */ |
||
| 91 | public function remove($group_id) |
||
| 95 | |||
| 96 | /** |
||
| 97 | * Create a new group. |
||
| 98 | * |
||
| 99 | * @param string $name |
||
| 100 | * @param string $external_id |
||
| 101 | * |
||
| 102 | * @return int|bool |
||
| 103 | */ |
||
| 104 | public function create($name, $external_id = '') |
||
| 111 | |||
| 112 | /** |
||
| 113 | * Update existing group. |
||
| 114 | * |
||
| 115 | * @param array $values |
||
| 116 | * |
||
| 117 | * @return bool |
||
| 118 | */ |
||
| 119 | public function update(array $values) |
||
| 123 | |||
| 124 | /** |
||
| 125 | * Get groupId from externalGroupId and create the group if not found. |
||
| 126 | * |
||
| 127 | * @param string $name |
||
| 128 | * @param string $external_id |
||
| 129 | * |
||
| 130 | * @return bool|int |
||
| 131 | */ |
||
| 132 | View Code Duplication | public function getOrCreateExternalGroupId($name, $external_id) |
|
| 142 | } |
||
| 143 |
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.