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 |
||
18 | { |
||
19 | /** |
||
20 | * @var \eZ\Publish\Core\MVC\Symfony\Matcher\ContentBased\Depth |
||
21 | */ |
||
22 | private $matcher; |
||
23 | |||
24 | protected function setUp() |
||
29 | |||
30 | /** |
||
31 | * @dataProvider matchLocationProvider |
||
32 | * @covers \eZ\Publish\Core\MVC\Symfony\Matcher\ContentBased\Depth::matchLocation |
||
33 | * @covers \eZ\Publish\Core\MVC\Symfony\Matcher\ContentBased\MultipleValued::setMatchingConfig |
||
34 | * |
||
35 | * @param int|int[] $matchingConfig |
||
36 | * @param \eZ\Publish\API\Repository\Values\Content\Location $location |
||
37 | * @param bool $expectedResult |
||
38 | */ |
||
39 | public function testMatchLocation($matchingConfig, Location $location, $expectedResult) |
||
44 | |||
45 | public function matchLocationProvider() |
||
80 | |||
81 | /** |
||
82 | * @dataProvider matchContentInfoProvider |
||
83 | * @covers eZ\Publish\Core\MVC\Symfony\Matcher\ContentBased\Depth::matchContentInfo |
||
84 | * @covers eZ\Publish\Core\MVC\Symfony\Matcher\ContentBased\MultipleValued::setMatchingConfig |
||
85 | * @covers \eZ\Publish\Core\MVC\RepositoryAware::setRepository |
||
86 | * |
||
87 | * @param int|int[] $matchingConfig |
||
88 | * @param \eZ\Publish\API\Repository\Repository $repository |
||
89 | * @param bool $expectedResult |
||
90 | */ |
||
91 | View Code Duplication | public function testMatchContentInfo($matchingConfig, Repository $repository, $expectedResult) |
|
100 | |||
101 | public function matchContentInfoProvider() |
||
126 | |||
127 | /** |
||
128 | * Returns a Repository mock configured to return the appropriate Location object with given parent location Id. |
||
129 | * |
||
130 | * @param int $depth |
||
131 | * |
||
132 | * @return \PHPUnit_Framework_MockObject_MockObject |
||
133 | */ |
||
134 | View Code Duplication | private function generateRepositoryMockForDepth($depth) |
|
135 | { |
||
136 | $locationServiceMock = $this |
||
137 | ->getMockBuilder('eZ\\Publish\\API\\Repository\\LocationService') |
||
138 | ->disableOriginalConstructor() |
||
139 | ->getMock(); |
||
140 | $locationServiceMock->expects($this->once()) |
||
141 | ->method('loadLocation') |
||
142 | ->with(42) |
||
143 | ->will( |
||
144 | $this->returnValue( |
||
145 | $this->getLocationMock(array('depth' => $depth)) |
||
146 | ) |
||
147 | ); |
||
148 | |||
149 | $repository = $this->getRepositoryMock(); |
||
150 | $repository |
||
151 | ->expects($this->once()) |
||
152 | ->method('getLocationService') |
||
153 | ->will($this->returnValue($locationServiceMock)); |
||
154 | $repository |
||
155 | ->expects($this->once()) |
||
156 | ->method('getPermissionResolver') |
||
157 | ->will($this->returnValue($this->getPermissionResolverMock())); |
||
158 | |||
159 | return $repository; |
||
162 |