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 MultiLineTextPagePartTest extends TestCase |
||
15 | { |
||
16 | /** |
||
17 | * @var MultiLineTextPagePart |
||
18 | */ |
||
19 | protected $object; |
||
20 | |||
21 | /** |
||
22 | * Sets up the fixture, for example, opens a network connection. |
||
23 | * This method is called before a test is executed. |
||
24 | */ |
||
25 | protected function setUp() |
||
26 | { |
||
27 | $this->object = new MultiLineTextPagePart(); |
||
28 | } |
||
29 | |||
30 | public function testSetGetRegex() |
||
37 | |||
38 | public function testSetGetErrorMessageRegex() |
||
45 | |||
46 | public function testGetDefaultView() |
||
52 | |||
53 | View Code Duplication | public function testAdaptForm() |
|
54 | { |
||
55 | $object = $this->object; |
||
56 | $object->setRequired(true); |
||
57 | $object->setRegex('.*example.*'); |
||
58 | |||
59 | $formBuilder = $this->getMockBuilder('Symfony\Component\Form\FormBuilder') |
||
60 | ->disableOriginalConstructor() |
||
61 | ->getMock(); |
||
62 | |||
63 | $formBuilder->expects($this->any()) |
||
64 | ->method('getData') |
||
65 | ->willReturn([]); |
||
66 | |||
67 | $fields = new ArrayObject(); |
||
68 | $object->setErrorMessageRequired('required'); |
||
69 | $object->setErrorMessageRegex('regex'); |
||
70 | $this->assertEquals(count($fields), 0); |
||
71 | /* @var FormBuilderInterface $formBuilder */ |
||
72 | $object->adaptForm($formBuilder, $fields, 0); |
||
73 | $this->assertTrue(count($fields) > 0); |
||
74 | $this->assertEquals('required', $object->getErrorMessageRequired()); |
||
75 | } |
||
76 | |||
77 | public function testGetDefaultAdminType() |
||
81 | |||
82 | public function testGetSetRequired() |
||
88 | } |
||
89 |
This method has been deprecated. The supplier of the class has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.