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 |
||
7 | class EmbeddedAssociationTest extends \Doctrine\Tests\ODM\CouchDB\CouchDBFunctionalTestCase |
||
8 | { |
||
9 | private $userId; |
||
10 | private $groupIds = array(); |
||
|
|||
11 | private $dm; |
||
12 | |||
13 | public function setUp() |
||
14 | { |
||
15 | $this->dm = $this->createDocumentManager(); |
||
16 | |||
17 | $user1 = new \Doctrine\Tests\Models\CMS\CmsUser(); |
||
18 | $user1->username = "beberlei"; |
||
19 | $user1->status = "active"; |
||
20 | $user1->name = "Benjamin"; |
||
21 | |||
22 | $user2 = new \Doctrine\Tests\Models\CMS\CmsUser(); |
||
23 | $user2->username = "lsmith"; |
||
24 | $user2->status = "active"; |
||
25 | $user2->name = "Lukas"; |
||
26 | |||
27 | $address1 = new \Doctrine\Tests\Models\CMS\CmsAddress(); |
||
28 | $address1->country = "Hungary"; |
||
29 | $address1->zip = "1122"; |
||
30 | $address1->city = "Budapest"; |
||
31 | $address1->mainAddress = true; |
||
32 | |||
33 | $user1->setAddress($address1); |
||
34 | |||
35 | $this->dm->persist($user1); |
||
36 | $this->dm->persist($user2); |
||
37 | |||
38 | $this->dm->flush(); |
||
39 | $this->dm->clear(); |
||
40 | |||
41 | $this->userId = $user1->id; |
||
42 | } |
||
43 | |||
44 | public function testShouldNotSaveUnchanged() |
||
59 | |||
60 | public function testSaveModifiedEmbedded() |
||
81 | |||
82 | public function testSaveEmbedded() |
||
104 | |||
105 | /** |
||
106 | * @group GH-80 |
||
107 | */ |
||
108 | public function testUpdateBooleanToFalseInEmbeddedDocument() |
||
123 | |||
124 | /** |
||
125 | * @group GH-80 |
||
126 | */ |
||
127 | View Code Duplication | public function testEmptyStringInEmbeddedDocument() |
|
139 | } |
||
140 | |||
155 |
This check marks private properties in classes that are never used. Those properties can be removed.