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 |
||
| 23 | class DescriptionFactoryTest extends \PHPUnit_Framework_TestCase |
||
| 24 | { |
||
| 25 | /** |
||
| 26 | * @covers ::__construct |
||
| 27 | * @covers ::create |
||
| 28 | * @uses phpDocumentor\Reflection\DocBlock\Description |
||
| 29 | * @dataProvider provideSimpleExampleDescriptions |
||
| 30 | */ |
||
| 31 | View Code Duplication | public function testDescriptionCanParseASimpleString($contents) |
|
| 41 | |||
| 42 | /** |
||
| 43 | * @covers ::__construct |
||
| 44 | * @covers ::create |
||
| 45 | * @uses phpDocumentor\Reflection\DocBlock\Description |
||
| 46 | * @dataProvider provideEscapeSequences |
||
| 47 | */ |
||
| 48 | View Code Duplication | public function testEscapeSequences($contents, $expected) |
|
| 58 | |||
| 59 | /** |
||
| 60 | * @covers ::__construct |
||
| 61 | * @covers ::create |
||
| 62 | * @uses phpDocumentor\Reflection\DocBlock\Description |
||
| 63 | * @uses phpDocumentor\Reflection\DocBlock\Tags\Link |
||
| 64 | * @uses phpDocumentor\Reflection\DocBlock\Tags\BaseTag |
||
| 65 | * @uses phpDocumentor\Reflection\DocBlock\Tags\Formatter\PassthroughFormatter |
||
| 66 | * @uses phpDocumentor\Reflection\Types\Context |
||
| 67 | */ |
||
| 68 | public function testDescriptionCanParseAStringWithInlineTag() |
||
| 84 | |||
| 85 | /** |
||
| 86 | * @covers ::__construct |
||
| 87 | * @covers ::create |
||
| 88 | * @uses phpDocumentor\Reflection\DocBlock\Description |
||
| 89 | * @uses phpDocumentor\Reflection\DocBlock\Tags\Link |
||
| 90 | * @uses phpDocumentor\Reflection\DocBlock\Tags\BaseTag |
||
| 91 | * @uses phpDocumentor\Reflection\DocBlock\Tags\Formatter\PassthroughFormatter |
||
| 92 | * @uses phpDocumentor\Reflection\Types\Context |
||
| 93 | */ |
||
| 94 | public function testDescriptionCanParseAStringStartingWithInlineTag() |
||
| 110 | |||
| 111 | /** |
||
| 112 | * @covers ::__construct |
||
| 113 | * @covers ::create |
||
| 114 | * @uses phpDocumentor\Reflection\DocBlock\Description |
||
| 115 | */ |
||
| 116 | View Code Duplication | public function testIfSuperfluousStartingSpacesAreRemoved() |
|
| 151 | |||
| 152 | /** |
||
| 153 | * Provides a series of example strings that the parser should correctly interpret and return. |
||
| 154 | * |
||
| 155 | * @return string[][] |
||
| 156 | */ |
||
| 157 | public function provideSimpleExampleDescriptions() |
||
| 166 | |||
| 167 | public function provideEscapeSequences() |
||
| 174 | } |
||
| 175 |
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.