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 |
||
20 | class ResolverByClassNameFunctionalTest extends AbstractHttpControllerTestCase |
||
21 | { |
||
22 | |||
23 | /** |
||
24 | * Данные для тестирования резолвинга на основе конфигов |
||
25 | * |
||
26 | * @return array |
||
27 | */ |
||
28 | public function dataResolveEntryNameByContext() |
||
68 | |||
69 | |||
70 | /** |
||
71 | * Тестирование резолвинга на основе конфига |
||
72 | * |
||
73 | * @dataProvider dataResolveEntryNameByContext |
||
74 | * |
||
75 | * @param $entryName |
||
76 | * @param $context |
||
77 | * @param $resolvedEntryName |
||
78 | * |
||
79 | * @throws \Zend\Stdlib\Exception\LogicException |
||
80 | * @throws \Zend\ServiceManager\Exception\ServiceNotFoundException |
||
81 | * @throws \Nnx\EntryNameResolver\Exception\InvalidContextException |
||
82 | */ |
||
83 | public function testResolveEntryNameByContext($entryName, $context, $resolvedEntryName) |
||
101 | |||
102 | |||
103 | /** |
||
104 | * Тестирование резолвинга на основе конфига |
||
105 | * |
||
106 | * @expectedExceptionMessage Context of type boolean is invalid; Context not string. |
||
107 | * @expectedException \Nnx\EntryNameResolver\Exception\InvalidContextException |
||
108 | * |
||
109 | * @throws \Zend\Stdlib\Exception\LogicException |
||
110 | * @throws \Zend\ServiceManager\Exception\ServiceNotFoundException |
||
111 | * @throws \Nnx\EntryNameResolver\Exception\InvalidContextException |
||
112 | */ |
||
113 | View Code Duplication | public function testResolveEntryNameByInvalidContext() |
|
129 | |||
130 | |||
131 | /** |
||
132 | * Тестирование резолвинга на основе конфига |
||
133 | * |
||
134 | * @throws \Zend\Stdlib\Exception\LogicException |
||
135 | * @throws \Zend\ServiceManager\Exception\ServiceNotFoundException |
||
136 | * @throws \Nnx\EntryNameResolver\Exception\InvalidContextException |
||
137 | * @throws \PHPUnit_Framework_AssertionFailedError |
||
138 | */ |
||
139 | public function testSetterGetterEntryBodyNamePattern() |
||
157 | } |
||
158 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.