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 |
||
13 | class Post extends ActiveRecordModel |
||
14 | { |
||
15 | |||
16 | /** |
||
17 | * @var string $tableName name of the database table. |
||
18 | */ |
||
19 | protected $tableName = "Posts"; |
||
20 | |||
21 | /** |
||
22 | * Columns in the table. |
||
23 | * |
||
24 | * @var integer $id primary key auto incremented. |
||
25 | */ |
||
26 | public $id; |
||
27 | public $posttitle; |
||
28 | public $postname; |
||
29 | public $posttext; |
||
30 | |||
31 | 1 | public function getInformation($name) |
|
36 | |||
37 | public function getAllInformationWhere($name) |
||
42 | |||
43 | public function checkId($id) |
||
48 | |||
49 | public function getPostInfo($params) |
||
57 | |||
58 | public function getTags($params) |
||
65 | |||
66 | View Code Duplication | public function getAllPosts() |
|
81 | |||
82 | public function getNext() |
||
86 | } |
||
87 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.