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 TestPost extends PHPUnit_Framework_TestCase |
||
| 19 | { |
||
| 20 | /** |
||
| 21 | * @Post $post |
||
| 22 | */ |
||
| 23 | private $post; |
||
| 24 | |||
| 25 | public function setUp() |
||
| 29 | |||
| 30 | /** |
||
| 31 | * @param $uuid |
||
| 32 | * @param $title |
||
| 33 | * @param $body |
||
| 34 | * @param $author |
||
| 35 | * @param $tags |
||
| 36 | * @param $publishDate |
||
| 37 | * @param $expected |
||
| 38 | * @param $message |
||
| 39 | * @dataProvider postConstructor |
||
| 40 | */ |
||
| 41 | public function testConstructor($uuid, $title, $body, $author, $tags, $publishDate, $expected, $message) |
||
| 46 | |||
| 47 | /** |
||
| 48 | * @param $date |
||
| 49 | * @param $expected |
||
| 50 | * @param $message |
||
| 51 | * @dataProvider publishDateProvider |
||
| 52 | */ |
||
| 53 | public function testPublishDates($date, $expected, $message) |
||
| 58 | |||
| 59 | /** |
||
| 60 | * @param $tags |
||
| 61 | * @param $tag |
||
| 62 | * @param $expected |
||
| 63 | * @param $message |
||
| 64 | * @dataProvider addTagProvider |
||
| 65 | */ |
||
| 66 | public function testAddTag($tags, $tag, $expected, $message) |
||
| 72 | |||
| 73 | /** |
||
| 74 | * @param $tags |
||
| 75 | * @param $tag |
||
| 76 | * @param $expected |
||
| 77 | * @param $message |
||
| 78 | * @dataProvider removeTagProvider |
||
| 79 | */ |
||
| 80 | public function testRemoveTag($tags, $tag, $expected, $message) |
||
| 86 | |||
| 87 | public function postConstructor() |
||
| 96 | |||
| 97 | public function publishDateProvider() |
||
| 106 | |||
| 107 | View Code Duplication | public function addTagProvider() |
|
| 118 | |||
| 119 | View Code Duplication | public function removeTagProvider() |
|
| 130 | } |
||
| 131 |
Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.