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 |
||
16 | { |
||
17 | /** @var \eZ\Publish\Core\MVC\Symfony\Matcher\ContentBased\UrlAlias */ |
||
18 | private $matcher; |
||
19 | |||
20 | protected function setUp() |
||
25 | |||
26 | /** |
||
27 | * @dataProvider setMatchingConfigProvider |
||
28 | * @covers \eZ\Publish\Core\MVC\Symfony\Matcher\ContentBased\UrlAlias::setMatchingConfig |
||
29 | * @covers \eZ\Publish\Core\MVC\Symfony\Matcher\ContentBased\MultipleValued::setMatchingConfig |
||
30 | * |
||
31 | * @param string $matchingConfig |
||
32 | * @param string[] $expectedValues |
||
33 | */ |
||
34 | public function testSetMatchingConfig($matchingConfig, $expectedValues) |
||
42 | |||
43 | public function setMatchingConfigProvider() |
||
44 | { |
||
45 | return [ |
||
46 | ['/foo/bar/', ['foo/bar']], |
||
47 | ['/foo/bar/', ['foo/bar']], |
||
48 | ['/foo/bar', ['foo/bar']], |
||
49 | [['/foo/bar/', 'baz/biz/'], ['foo/bar', 'baz/biz']], |
||
50 | [['foo/bar', 'baz/biz'], ['foo/bar', 'baz/biz']], |
||
51 | ]; |
||
52 | } |
||
53 | |||
54 | /** |
||
55 | * Returns a Repository mock configured to return the appropriate Section object with given section identifier. |
||
56 | * |
||
57 | * @param string $path |
||
58 | * |
||
59 | * @return \PHPUnit\Framework\MockObject\MockObject |
||
60 | */ |
||
61 | private function generateRepositoryMockForUrlAlias($path) |
||
97 | |||
98 | /** |
||
99 | * @dataProvider matchLocationProvider |
||
100 | * @covers \eZ\Publish\Core\MVC\Symfony\Matcher\ContentBased\UrlAlias::matchLocation |
||
101 | * @covers \eZ\Publish\Core\MVC\Symfony\Matcher\ContentBased\UrlAlias::setMatchingConfig |
||
102 | * @covers \eZ\Publish\Core\MVC\RepositoryAware::setRepository |
||
103 | * |
||
104 | * @param string|string[] $matchingConfig |
||
105 | * @param \eZ\Publish\API\Repository\Repository $repository |
||
106 | * @param bool $expectedResult |
||
107 | */ |
||
108 | View Code Duplication | public function testMatchLocation($matchingConfig, Repository $repository, $expectedResult) |
|
117 | |||
118 | public function matchLocationProvider() |
||
148 | |||
149 | /** |
||
150 | * @expectedException \RuntimeException |
||
151 | * @covers \eZ\Publish\Core\MVC\Symfony\Matcher\ContentBased\UrlAlias::matchContentInfo |
||
152 | * @covers \eZ\Publish\Core\MVC\Symfony\Matcher\ContentBased\UrlAlias::setMatchingConfig |
||
153 | */ |
||
154 | public function testMatchContentInfo() |
||
159 | } |
||
160 |