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 |
||
| 8 | class TComplexTypePropertyTypeTest extends TestCase |
||
| 9 | { |
||
| 10 | public function testConcurrencyModeNonString() |
||
| 11 | { |
||
| 12 | $foo = new TComplexTypePropertyType(); |
||
| 13 | |||
| 14 | $mode = new \DateTime(); |
||
| 15 | $expected = 'Input must be a string: AlgoWeb\\ODataMetadata\\MetadataV3\\edm\\TComplexTypePropertyType'; |
||
| 16 | $actual = null; |
||
| 17 | |||
| 18 | try { |
||
| 19 | $foo->isTConcurrencyModeValid($mode); |
||
| 20 | } catch (\InvalidArgumentException $e) { |
||
| 21 | $actual = $e->getMessage(); |
||
| 22 | } |
||
| 23 | $this->assertEquals($expected, $actual); |
||
| 24 | } |
||
| 25 | |||
| 26 | public function testConcurrencyModeFixed() |
||
| 27 | { |
||
| 28 | $foo = new TComplexTypePropertyType(); |
||
| 29 | |||
| 30 | $mode = 'Fixed'; |
||
| 31 | $this->assertTrue($foo->isTConcurrencyModeValid($mode)); |
||
| 32 | } |
||
| 33 | |||
| 34 | public function testConcurrencyModeNone() |
||
| 35 | { |
||
| 36 | $foo = new TComplexTypePropertyType(); |
||
| 37 | |||
| 38 | $mode = 'None'; |
||
| 39 | $this->assertTrue($foo->isTConcurrencyModeValid($mode)); |
||
| 40 | } |
||
| 41 | } |
||
| 42 |