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 |
||
| 7 | class ExcludeTest extends SerializerTestCase |
||
| 8 | { |
||
| 9 | public function testSerialize() |
||
| 10 | { |
||
| 11 | $data = $this->serialize(new Car(true)); |
||
| 12 | |||
| 13 | $this->assertFalse(isset($data['model'])); |
||
| 14 | $this->assertTrue(isset($data['size'])); |
||
| 15 | } |
||
| 16 | |||
| 17 | public function testDeserialize() |
||
| 18 | { |
||
| 19 | $data = ['model' => 'model_value', 'size' => 'size_value']; |
||
| 20 | $obj = $this->deserialize($data, Car::class); |
||
| 21 | |||
| 22 | $this->assertPropertyValue($obj, 'model', null); |
||
| 23 | $this->assertPropertyValue($obj, 'size', 'size_value'); |
||
| 24 | } |
||
| 25 | } |
||
| 26 |