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 |
||
5 | class PotatoModel |
||
6 | { |
||
7 | /** |
||
8 | * [$queryTo The query (instance of PotatoQuery) to handle all database queries. |
||
9 | * |
||
10 | * @var [type] Instance of potatoQuery class, to be difined during construction. |
||
11 | */ |
||
12 | public $queryTo; |
||
13 | |||
14 | /** |
||
15 | * [$dataToSave The properties of a object of theis class to be saved in the database. |
||
16 | * |
||
17 | * @var array This is an array of property names to be saved in to the database. |
||
18 | */ |
||
19 | public $dataToSave = []; |
||
20 | |||
21 | /** |
||
22 | * [__construct The constructor to initialize public variables]. |
||
23 | * |
||
24 | * @param PotatoQuery|null $potatoQuery The query to be used for the communication with the databse. |
||
25 | */ |
||
26 | public function __construct(PotatoQuery $potatoQuery = null) |
||
30 | |||
31 | /** |
||
32 | * [__set magic Property to set put of the object into the arary of properties to be saved in the database.]. |
||
33 | * |
||
34 | * @param [type] $property [The property of the object to be saved.] |
||
|
|||
35 | * @param [type] $value [The value of given property to be saved.] |
||
36 | */ |
||
37 | public function __set($property, $value) |
||
41 | |||
42 | /** |
||
43 | * [__get Magic function to get the property from the dataToSave array, the array of properties.]. |
||
44 | * |
||
45 | * @param [type] $property [The property to be gotten from the data to save array of propoerties.] |
||
46 | * |
||
47 | * @return [type] [If the property is cound, return the value of that property. Otherwise throw an exception] |
||
48 | */ |
||
49 | public function __get($property) |
||
57 | |||
58 | /** |
||
59 | * [__isset Magic function to check if the given propertyh of the object is set.]. |
||
60 | * |
||
61 | * @param [type] $property [The property in question] |
||
62 | * |
||
63 | * @return bool True if the property exists. False otherwise. |
||
64 | */ |
||
65 | public function __isset($property) |
||
69 | |||
70 | /** |
||
71 | * [getAll Get all records of database table corresponding the the called class name. |
||
72 | * |
||
73 | * @param [type] $query [The query to be used to communicated with the databse.] |
||
74 | * |
||
75 | * @return [type] Return the returned value of the query's query. The return value is an array of records represented as objects. |
||
76 | */ |
||
77 | public static function getAll($query = null) |
||
84 | |||
85 | /** |
||
86 | * [find Find on record or row in the table given by an ID. |
||
87 | * |
||
88 | * @param [type] $id [the ID of the row record to be fetched.] |
||
89 | * @param [type] $query [The query to be used for the database communication.] |
||
90 | * |
||
91 | * @return [type] [The returned value of finding the record with the given ID.] |
||
92 | */ |
||
93 | View Code Duplication | public static function find($id, $query = null) |
|
100 | |||
101 | /** |
||
102 | * SAve a recrd into the database. Saveing is either inserting or updating. |
||
103 | * |
||
104 | * @return [type] [A newly inserted record ot a recently updated record in the database.] |
||
105 | */ |
||
106 | public function save() |
||
110 | |||
111 | /** |
||
112 | * Check if the object to be saved has an ID. |
||
113 | * |
||
114 | * @return bool [description] |
||
115 | */ |
||
116 | public function isStored() |
||
120 | |||
121 | /** |
||
122 | * Insert a new record into the database while communicating with the qury handler. |
||
123 | * |
||
124 | * @return [type] [The returned value of the quering the databse.] |
||
125 | */ |
||
126 | public function insert() |
||
132 | |||
133 | /** |
||
134 | * Update a record in a database. The record must have an ID before it can be updated. |
||
135 | * |
||
136 | * @return [type] [description] |
||
137 | */ |
||
138 | public function update() |
||
144 | |||
145 | /** |
||
146 | * Destroy a recored or row from a database table. |
||
147 | * |
||
148 | * @param [type] $id [The ID of the record to be deleted.] |
||
149 | * @param [type] $query [The query to handle to deleting operation] |
||
150 | * |
||
151 | * @return [type] [An array of all the records in that table without the deleted recode.] |
||
152 | */ |
||
153 | View Code Duplication | public static function destroy($id, $query = null) |
|
161 | |||
162 | /** |
||
163 | * [getClassTableName Get the name of the class from which this function is called, including classes that inherit from this class.]. |
||
164 | * |
||
165 | * @return [type] [description] |
||
166 | */ |
||
167 | public static function getClassTableName() |
||
174 | } |
||
175 |
This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.