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 |
||
20 | class UserTest extends UnitTestCase |
||
21 | { |
||
22 | //<editor-fold desc="Public Methods"> |
||
23 | /** |
||
24 | * @covers \Tfboe\FmLib\Entity\Traits\User::init |
||
25 | * @uses \Tfboe\FmLib\Entity\Traits\User::getJWTCustomClaims |
||
26 | * @uses \Tfboe\FmLib\Entity\Traits\User::getJwtVersion |
||
27 | * @uses \Tfboe\FmLib\Entity\Traits\User::getConfirmedAGBVersion |
||
28 | */ |
||
29 | public function testConstructor() |
||
37 | |||
38 | /** |
||
39 | * @covers \Tfboe\FmLib\Entity\Traits\User::setEmail |
||
40 | * @covers \Tfboe\FmLib\Entity\Traits\User::getEmail |
||
41 | * @uses \Tfboe\FmLib\Entity\Traits\User::init |
||
42 | */ |
||
43 | public function testEmail() |
||
49 | |||
50 | /** |
||
51 | * @covers \Tfboe\FmLib\Entity\Traits\User::getJWTCustomClaims |
||
52 | * @uses \Tfboe\FmLib\Entity\Traits\User::setJwtVersion |
||
53 | * @uses \Tfboe\FmLib\Entity\Traits\User::init |
||
54 | */ |
||
55 | public function testJWTCustomClaims() |
||
61 | |||
62 | /** |
||
63 | * @covers \Tfboe\FmLib\Entity\Traits\User::getJWTIdentifier |
||
64 | * @uses \Tfboe\FmLib\Entity\Traits\User::init |
||
65 | * @uses \Tfboe\FmLib\Entity\Helpers\UUIDEntity::getId |
||
66 | */ |
||
67 | View Code Duplication | public function testJWTIdentifier() |
|
75 | |||
76 | /** |
||
77 | * @covers \Tfboe\FmLib\Entity\Traits\User::getJwtVersion() |
||
78 | * @covers \Tfboe\FmLib\Entity\Traits\User::setJwtVersion |
||
79 | * @uses \Tfboe\FmLib\Entity\Traits\User::init |
||
80 | */ |
||
81 | public function testJwtVersion() |
||
87 | |||
88 | /** |
||
89 | * @covers \Tfboe\FmLib\Entity\Traits\User::getConfirmedAGBVersion |
||
90 | * @covers \Tfboe\FmLib\Entity\Traits\User::setConfirmedAGBVersion |
||
91 | * @uses \Tfboe\FmLib\Entity\Traits\User::init |
||
92 | */ |
||
93 | public function testLastConfirmedAGBVersion() |
||
99 | //</editor-fold desc="Public Methods"> |
||
100 | |||
101 | //<editor-fold desc="Private Methods"> |
||
102 | /** |
||
103 | * @return UserInterface a new user |
||
104 | */ |
||
105 | private function user(): UserInterface |
||
109 | //</editor-fold desc="Private Methods"> |
||
110 | } |
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.