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 |
||
15 | class SectionTest extends BaseTest |
||
16 | { |
||
17 | /** @var \eZ\Publish\Core\MVC\Symfony\Matcher\ContentBased\Identifier\Section */ |
||
18 | private $matcher; |
||
19 | |||
20 | protected function setUp() |
||
25 | |||
26 | /** |
||
27 | * Returns a Repository mock configured to return the appropriate Section object with given section identifier. |
||
28 | * |
||
29 | * @param string $sectionIdentifier |
||
30 | * |
||
31 | * @return \PHPUnit\Framework\MockObject\MockObject |
||
32 | */ |
||
33 | View Code Duplication | private function generateRepositoryMockForSectionIdentifier($sectionIdentifier) |
|
63 | |||
64 | /** |
||
65 | * @dataProvider matchSectionProvider |
||
66 | * @covers \eZ\Publish\Core\MVC\Symfony\Matcher\ContentBased\Identifier\Section::matchLocation |
||
67 | * @covers \eZ\Publish\Core\MVC\Symfony\Matcher\ContentBased\MultipleValued::setMatchingConfig |
||
68 | * @covers \eZ\Publish\Core\MVC\RepositoryAware::setRepository |
||
69 | * |
||
70 | * @param string|string[] $matchingConfig |
||
71 | * @param \eZ\Publish\API\Repository\Repository $repository |
||
72 | * @param bool $expectedResult |
||
73 | */ |
||
74 | public function testMatchLocation($matchingConfig, Repository $repository, $expectedResult) |
||
92 | |||
93 | public function matchSectionProvider() |
||
118 | |||
119 | /** |
||
120 | * @dataProvider matchSectionProvider |
||
121 | * @covers \eZ\Publish\Core\MVC\Symfony\Matcher\ContentBased\Identifier\Section::matchContentInfo |
||
122 | * @covers \eZ\Publish\Core\MVC\Symfony\Matcher\ContentBased\MultipleValued::setMatchingConfig |
||
123 | * @covers \eZ\Publish\Core\MVC\RepositoryAware::setRepository |
||
124 | * |
||
125 | * @param string|string[] $matchingConfig |
||
126 | * @param \eZ\Publish\API\Repository\Repository $repository |
||
127 | * @param bool $expectedResult |
||
128 | */ |
||
129 | View Code Duplication | public function testMatchContentInfo($matchingConfig, Repository $repository, $expectedResult) |
|
138 | } |
||
139 |