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 |
||
| 18 | class UserTest extends PHPUnit_Framework_TestCase |
||
| 19 | { |
||
| 20 | use ChangeProtectedAttribute; |
||
| 21 | |||
| 22 | /** |
||
| 23 | * @return multitype:multitype:number |
||
|
|
|||
| 24 | */ |
||
| 25 | View Code Duplication | public function validObjects() |
|
| 40 | |||
| 41 | /** |
||
| 42 | * @return multitype:multitype:number |
||
| 43 | */ |
||
| 44 | View Code Duplication | public function invalidObjects() |
|
| 59 | |||
| 60 | /** |
||
| 61 | * @test |
||
| 62 | * @dataProvider validObjects |
||
| 63 | * @covers \User\Entity\User::setName |
||
| 64 | */ |
||
| 65 | public function setNameReturnEmptyOnSuccess($obj) |
||
| 73 | |||
| 74 | /** |
||
| 75 | * @test |
||
| 76 | * @dataProvider invalidObjects |
||
| 77 | * @covers \User\Entity\User::setName |
||
| 78 | * @expectedException \InvalidArgumentException |
||
| 79 | */ |
||
| 80 | public function setNameThrowsExceptionWhenEmpty($obj) |
||
| 85 | |||
| 86 | /** |
||
| 87 | * @test |
||
| 88 | * @dataProvider validObjects |
||
| 89 | * @covers \User\Entity\User::getName |
||
| 90 | */ |
||
| 91 | public function getNameReturnNameAttribute($obj) |
||
| 99 | |||
| 100 | /** |
||
| 101 | * @test |
||
| 102 | * @dataProvider validObjects |
||
| 103 | * @covers \User\Entity\User::getEmail |
||
| 104 | */ |
||
| 105 | public function getEmailReturnEmailAttribute($obj) |
||
| 113 | |||
| 114 | /** |
||
| 115 | * @test |
||
| 116 | * @dataProvider validObjects |
||
| 117 | * @covers \User\Entity\User::setEmail |
||
| 118 | */ |
||
| 119 | public function setEmailReturnEmptyOnSuccess($obj) |
||
| 127 | |||
| 128 | /** |
||
| 129 | * @test |
||
| 130 | * @dataProvider invalidObjects |
||
| 131 | * @covers \User\Entity\User::setEmail |
||
| 132 | * @expectedException \InvalidArgumentException |
||
| 133 | */ |
||
| 134 | public function setEmailThrowsInvalidArgumentExceptoinWhenInvalid($obj) |
||
| 139 | } |
||
| 140 |
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.