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 PureNegativeQueryTest extends BaseTest  | 
            ||
| 21 | { | 
            ||
| 22 | public function providerForTestMatchAll()  | 
            ||
| 23 |     { | 
            ||
| 24 | $query = new Query(['filter' => new Criterion\MatchAll()]);  | 
            ||
| 25 | $result = $this->getRepository()->getSearchService()->findContent($query);  | 
            ||
| 26 | // Sanity check  | 
            ||
| 27 | $this->assertGreaterThan(0, $result->totalCount);  | 
            ||
| 28 | $totalCount = $result->totalCount;  | 
            ||
| 29 | $contentId = 12;  | 
            ||
| 30 | |||
| 31 | return [  | 
            ||
| 32 | [  | 
            ||
| 33 | new Criterion\LogicalOr(  | 
            ||
| 34 | [  | 
            ||
| 35 | new Criterion\ContentId($contentId),  | 
            ||
| 36 | new Criterion\MatchNone(),  | 
            ||
| 37 | ]  | 
            ||
| 38 | ),  | 
            ||
| 39 | 1,  | 
            ||
| 40 | ],  | 
            ||
| 41 | [  | 
            ||
| 42 | new Criterion\LogicalAnd(  | 
            ||
| 43 | [  | 
            ||
| 44 | new Criterion\ContentId($contentId),  | 
            ||
| 45 | new Criterion\MatchNone(),  | 
            ||
| 46 | ]  | 
            ||
| 47 | ),  | 
            ||
| 48 | 0,  | 
            ||
| 49 | ],  | 
            ||
| 50 | [  | 
            ||
| 51 | new Criterion\LogicalOr(  | 
            ||
| 52 | [  | 
            ||
| 53 | new Criterion\ContentId($contentId),  | 
            ||
| 54 | new Criterion\LogicalNot(  | 
            ||
| 55 | new Criterion\MatchAll()  | 
            ||
| 56 | ),  | 
            ||
| 57 | ]  | 
            ||
| 58 | ),  | 
            ||
| 59 | 1,  | 
            ||
| 60 | ],  | 
            ||
| 61 | [  | 
            ||
| 62 | new Criterion\LogicalAnd(  | 
            ||
| 63 | [  | 
            ||
| 64 | new Criterion\ContentId($contentId),  | 
            ||
| 65 | new Criterion\LogicalNot(  | 
            ||
| 66 | new Criterion\MatchAll()  | 
            ||
| 67 | ),  | 
            ||
| 68 | ]  | 
            ||
| 69 | ),  | 
            ||
| 70 | 0,  | 
            ||
| 71 | ],  | 
            ||
| 72 | [  | 
            ||
| 73 | new Criterion\LogicalOr(  | 
            ||
| 74 | [  | 
            ||
| 75 | new Criterion\ContentId($contentId),  | 
            ||
| 76 | new Criterion\MatchAll(),  | 
            ||
| 77 | ]  | 
            ||
| 78 | ),  | 
            ||
| 79 | $totalCount,  | 
            ||
| 80 | ],  | 
            ||
| 81 | [  | 
            ||
| 82 | new Criterion\LogicalAnd(  | 
            ||
| 83 | [  | 
            ||
| 84 | new Criterion\ContentId($contentId),  | 
            ||
| 85 | new Criterion\MatchAll(),  | 
            ||
| 86 | ]  | 
            ||
| 87 | ),  | 
            ||
| 88 | 1,  | 
            ||
| 89 | ],  | 
            ||
| 90 | [  | 
            ||
| 91 | new Criterion\LogicalOr(  | 
            ||
| 92 | [  | 
            ||
| 93 | new Criterion\MatchAll(),  | 
            ||
| 94 | new Criterion\MatchNone(),  | 
            ||
| 95 | ]  | 
            ||
| 96 | ),  | 
            ||
| 97 | $totalCount,  | 
            ||
| 98 | ],  | 
            ||
| 99 | [  | 
            ||
| 100 | new Criterion\LogicalAnd(  | 
            ||
| 101 | [  | 
            ||
| 102 | new Criterion\MatchAll(),  | 
            ||
| 103 | new Criterion\MatchNone(),  | 
            ||
| 104 | ]  | 
            ||
| 105 | ),  | 
            ||
| 106 | 0,  | 
            ||
| 107 | ],  | 
            ||
| 108 | [  | 
            ||
| 109 | new Criterion\LogicalOr(  | 
            ||
| 110 | [  | 
            ||
| 111 | new Criterion\ContentId($contentId),  | 
            ||
| 112 | new Criterion\LogicalNot(  | 
            ||
| 113 | new Criterion\ContentId($contentId)  | 
            ||
| 114 | ),  | 
            ||
| 115 | ]  | 
            ||
| 116 | ),  | 
            ||
| 117 | $totalCount,  | 
            ||
| 118 | ],  | 
            ||
| 119 | [  | 
            ||
| 120 | new Criterion\LogicalOr(  | 
            ||
| 121 | [  | 
            ||
| 122 | new Criterion\ContentId($contentId),  | 
            ||
| 123 | new Criterion\LogicalNot(  | 
            ||
| 124 | new Criterion\LogicalNot(  | 
            ||
| 125 | new Criterion\ContentId($contentId)  | 
            ||
| 126 | )  | 
            ||
| 127 | ),  | 
            ||
| 128 | ]  | 
            ||
| 129 | ),  | 
            ||
| 130 | 1,  | 
            ||
| 131 | ],  | 
            ||
| 132 | [  | 
            ||
| 133 | new Criterion\LogicalOr(  | 
            ||
| 134 | [  | 
            ||
| 135 | new Criterion\LogicalNot(  | 
            ||
| 136 | new Criterion\ContentId($contentId)  | 
            ||
| 137 | ),  | 
            ||
| 138 | new Criterion\LogicalNot(  | 
            ||
| 139 | new Criterion\LogicalNot(  | 
            ||
| 140 | new Criterion\ContentId($contentId)  | 
            ||
| 141 | )  | 
            ||
| 142 | ),  | 
            ||
| 143 | ]  | 
            ||
| 144 | ),  | 
            ||
| 145 | $totalCount,  | 
            ||
| 146 | ],  | 
            ||
| 147 | [  | 
            ||
| 148 | new Criterion\LogicalOr(  | 
            ||
| 149 | [  | 
            ||
| 150 | new Criterion\LogicalNot(  | 
            ||
| 151 | new Criterion\ContentId($contentId)  | 
            ||
| 152 | ),  | 
            ||
| 153 | new Criterion\LogicalNot(  | 
            ||
| 154 | new Criterion\ContentId($contentId)  | 
            ||
| 155 | ),  | 
            ||
| 156 | ]  | 
            ||
| 157 | ),  | 
            ||
| 158 | $totalCount - 1,  | 
            ||
| 159 | ],  | 
            ||
| 160 | [  | 
            ||
| 161 | new Criterion\LogicalAnd(  | 
            ||
| 162 | [  | 
            ||
| 163 | new Criterion\ContentId($contentId),  | 
            ||
| 164 | new Criterion\LogicalNot(  | 
            ||
| 165 | new Criterion\ContentId($contentId)  | 
            ||
| 166 | ),  | 
            ||
| 167 | ]  | 
            ||
| 168 | ),  | 
            ||
| 169 | 0,  | 
            ||
| 170 | ],  | 
            ||
| 171 | [  | 
            ||
| 172 | new Criterion\LogicalAnd(  | 
            ||
| 173 | [  | 
            ||
| 174 | |||
| 175 | new Criterion\ContentId($contentId),  | 
            ||
| 176 | new Criterion\LogicalNot(  | 
            ||
| 177 | new Criterion\LogicalNot(  | 
            ||
| 178 | new Criterion\ContentId($contentId)  | 
            ||
| 179 | )  | 
            ||
| 180 | ),  | 
            ||
| 181 | ]  | 
            ||
| 182 | ),  | 
            ||
| 183 | 1,  | 
            ||
| 184 | ],  | 
            ||
| 185 | [  | 
            ||
| 186 | new Criterion\LogicalAnd(  | 
            ||
| 187 | [  | 
            ||
| 188 | new Criterion\LogicalNot(  | 
            ||
| 189 | new Criterion\ContentId($contentId)  | 
            ||
| 190 | ),  | 
            ||
| 191 | new Criterion\LogicalNot(  | 
            ||
| 192 | new Criterion\LogicalNot(  | 
            ||
| 193 | new Criterion\ContentId($contentId)  | 
            ||
| 194 | )  | 
            ||
| 195 | ),  | 
            ||
| 196 | ]  | 
            ||
| 197 | ),  | 
            ||
| 198 | 0,  | 
            ||
| 199 | ],  | 
            ||
| 200 | [  | 
            ||
| 201 | new Criterion\LogicalAnd(  | 
            ||
| 202 | [  | 
            ||
| 203 | new Criterion\LogicalNot(  | 
            ||
| 204 | new Criterion\ContentId($contentId)  | 
            ||
| 205 | ),  | 
            ||
| 206 | new Criterion\LogicalNot(  | 
            ||
| 207 | new Criterion\ContentId($contentId)  | 
            ||
| 208 | ),  | 
            ||
| 209 | ]  | 
            ||
| 210 | ),  | 
            ||
| 211 | $totalCount - 1,  | 
            ||
| 212 | ],  | 
            ||
| 213 | ];  | 
            ||
| 214 | }  | 
            ||
| 215 | |||
| 216 | /**  | 
            ||
| 217 | * @dataProvider providerForTestMatchAll  | 
            ||
| 218 | *  | 
            ||
| 219 | * @param \eZ\Publish\API\Repository\Values\Content\Query\Criterion $criterion  | 
            ||
| 220 | * @param int $totalCount  | 
            ||
| 221 | */  | 
            ||
| 222 | View Code Duplication | public function testMatchAllContentInfoQuery($criterion, $totalCount)  | 
            |
| 234 | |||
| 235 | /**  | 
            ||
| 236 | * @dataProvider providerForTestMatchAll  | 
            ||
| 237 | *  | 
            ||
| 238 | * @param \eZ\Publish\API\Repository\Values\Content\Query\Criterion $criterion  | 
            ||
| 239 | * @param int $totalCount  | 
            ||
| 240 | */  | 
            ||
| 241 | View Code Duplication | public function testMatchAllContentInfoFilter($criterion, $totalCount)  | 
            |
| 253 | |||
| 254 | /**  | 
            ||
| 255 | * @dataProvider providerForTestMatchAll  | 
            ||
| 256 | *  | 
            ||
| 257 | * @param \eZ\Publish\API\Repository\Values\Content\Query\Criterion $criterion  | 
            ||
| 258 | * @param int $totalCount  | 
            ||
| 259 | */  | 
            ||
| 260 | View Code Duplication | public function testMatchAllLocationQuery($criterion, $totalCount)  | 
            |
| 272 | |||
| 273 | /**  | 
            ||
| 274 | * @dataProvider providerForTestMatchAll  | 
            ||
| 275 | *  | 
            ||
| 276 | * @param \eZ\Publish\API\Repository\Values\Content\Query\Criterion $criterion  | 
            ||
| 277 | * @param int $totalCount  | 
            ||
| 278 | */  | 
            ||
| 279 | View Code Duplication | public function testMatchAllLocationFilter($criterion, $totalCount)  | 
            |
| 291 | }  | 
            ||
| 292 |