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 |
||
| 14 | class UseImperativeMoodTest extends \PHPUnit_Framework_TestCase |
||
| 15 | { |
||
| 16 | /** |
||
| 17 | * Tests UseImperativeMood::pass |
||
| 18 | */ |
||
| 19 | public function testPassSuccess() |
||
| 20 | { |
||
| 21 | $msg = new CommitMessage('Foo bar baz'); |
||
| 22 | $rule = new UseImperativeMood(); |
||
| 23 | $this->assertTrue($rule->pass($msg)); |
||
| 24 | } |
||
| 25 | |||
| 26 | /** |
||
| 27 | * Tests UseImperativeMood::pass |
||
| 28 | */ |
||
| 29 | public function testPassFail() |
||
| 30 | { |
||
| 31 | $msg = new CommitMessage('Added some something'); |
||
| 32 | $rule = new UseImperativeMood(); |
||
| 33 | $this->assertFalse($rule->pass($msg)); |
||
| 34 | |||
| 35 | $hint = $rule->getHint(); |
||
| 36 | $this->assertTrue((bool) strpos($hint, 'imperative')); |
||
| 37 | } |
||
| 38 | } |
||
| 39 |