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 |
||
22 | class AbstractTestCase extends LanguageAwareTestCase |
||
23 | { |
||
24 | private static $setup; |
||
25 | |||
26 | /** |
||
27 | * Field registry mock. |
||
28 | * |
||
29 | * @var \eZ\Publish\Core\Persistence\Legacy\Content\FieldValue\ConverterRegistry |
||
30 | */ |
||
31 | private $converterRegistry; |
||
32 | |||
33 | /** @var \eZ\Publish\SPI\Persistence\Content\Type\Handler */ |
||
34 | private $contentTypeHandler; |
||
35 | |||
36 | /** |
||
37 | * Only set up once for these read only tests on a large fixture. |
||
38 | * |
||
39 | * Skipping the reset-up, since setting up for these tests takes quite some |
||
40 | * time, which is not required to spent, since we are only reading from the |
||
41 | * database anyways. |
||
42 | */ |
||
43 | public function setUp() |
||
54 | |||
55 | /** |
||
56 | * Assert that the elements are. |
||
57 | */ |
||
58 | protected function assertSearchResults($expectedIds, $searchResult) |
||
63 | |||
64 | View Code Duplication | protected function getIds($searchResult) |
|
65 | { |
||
66 | $ids = array_map( |
||
67 | function ($hit) { |
||
68 | return $hit->valueObject->id; |
||
69 | }, |
||
70 | $searchResult->searchHits |
||
71 | ); |
||
72 | |||
73 | sort($ids); |
||
74 | |||
75 | return $ids; |
||
76 | } |
||
77 | |||
78 | protected function getContentTypeHandler() |
||
94 | |||
95 | View Code Duplication | protected function getConverterRegistry() |
|
118 | } |
||
119 |