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 |
||
| 9 | class Test_Affiliate extends TestCase { |
||
| 10 | |||
| 11 | /** |
||
| 12 | * Mock affiliate code. |
||
| 13 | * |
||
| 14 | * @var string |
||
| 15 | */ |
||
| 16 | private $aff_code = 'abc123'; |
||
| 17 | |||
| 18 | /** |
||
| 19 | * Test teardown. |
||
| 20 | */ |
||
| 21 | public function tearDown() { |
||
| 24 | |||
| 25 | View Code Duplication | function test_affiliate_code_missing() { |
|
| 44 | |||
| 45 | View Code Duplication | function test_affiliate_code_exists() { |
|
| 64 | |||
| 65 | /** |
||
| 66 | * Mock a global function with particular arguments and make it return a certain value. |
||
| 67 | * |
||
| 68 | * @param string $function_name Name of the function. |
||
| 69 | * @param array $args Array of argument sets, last value of each set is used as a return value. |
||
| 70 | * @return phpmock\Mock The mock object. |
||
| 71 | */ |
||
| 72 | View Code Duplication | protected function mock_function_with_args( $function_name, $args = array() ) { |
|
| 93 | |||
| 94 | } |
||
| 95 |