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 |
||
3 | View Code Duplication | class ExternalCommentFixture extends CakeTestFixture { |
|
4 | |||
5 | public $useDbConfig = 'test_external'; |
||
6 | |||
7 | /** |
||
8 | * fields property |
||
9 | * |
||
10 | * @var array |
||
11 | */ |
||
12 | public $fields = array( |
||
13 | 'id' => array('type' => 'integer', 'key' => 'primary'), |
||
14 | 'article_id' => array('type' => 'integer', 'null' => true), |
||
15 | 'comment' => 'text', |
||
16 | ); |
||
17 | |||
18 | /** |
||
19 | * records property |
||
20 | * |
||
21 | * @var array |
||
22 | */ |
||
23 | public $records = array( |
||
24 | array('article_id' => '3', 'comment' => 'External Comment'), |
||
25 | ); |
||
26 | } |
||
27 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.