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 |
||
31 | class SearchService implements SearchServiceInterface, SearchServiceSortClauseInterface |
||
|
|||
32 | { |
||
33 | /** |
||
34 | * @var \eZ\Publish\Core\Repository\Repository |
||
35 | */ |
||
36 | protected $repository; |
||
37 | |||
38 | /** |
||
39 | * @var \eZ\Publish\SPI\Search\Handler |
||
40 | */ |
||
41 | protected $searchHandler; |
||
42 | |||
43 | /** |
||
44 | * @var array |
||
45 | */ |
||
46 | protected $settings; |
||
47 | |||
48 | /** |
||
49 | * @var \eZ\Publish\Core\Repository\Helper\DomainMapper |
||
50 | */ |
||
51 | protected $domainMapper; |
||
52 | |||
53 | /** |
||
54 | * @var \eZ\Publish\Core\Repository\PermissionsCriterionHandler |
||
55 | */ |
||
56 | protected $permissionsCriterionHandler; |
||
57 | |||
58 | /** |
||
59 | * @var \eZ\Publish\Core\Repository\Mapper\SortClauseMapper |
||
60 | */ |
||
61 | protected $sortClauseMapper; |
||
62 | |||
63 | /** |
||
64 | * Setups service with reference to repository object that created it & corresponding handler. |
||
65 | * |
||
66 | * @param \eZ\Publish\API\Repository\Repository $repository |
||
67 | * @param \eZ\Publish\SPI\Search\Handler $searchHandler |
||
68 | * @param \eZ\Publish\Core\Repository\Helper\DomainMapper $domainMapper |
||
69 | * @param \eZ\Publish\Core\Repository\PermissionsCriterionHandler $permissionsCriterionHandler |
||
70 | * @param \eZ\Publish\Core\Repository\Mapper\SortClauseMapper $sortClauseMapper |
||
71 | * @param array $settings |
||
72 | */ |
||
73 | public function __construct( |
||
91 | |||
92 | /** |
||
93 | * Finds content objects for the given query. |
||
94 | * |
||
95 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if query is not valid |
||
96 | * |
||
97 | * @param \eZ\Publish\API\Repository\Values\Content\Query $query |
||
98 | * @param array $languageFilter Configuration for specifying prioritized languages query will be performed on. |
||
99 | * Currently supports: <code>array("languages" => array(<language1>,..), "useAlwaysAvailable" => bool)</code> |
||
100 | * useAlwaysAvailable defaults to true to avoid exceptions on missing translations. |
||
101 | * @param bool $filterOnUserPermissions if true only the objects which the user is allowed to read are returned. |
||
102 | * |
||
103 | * @return \eZ\Publish\API\Repository\Values\Content\Search\SearchResult |
||
104 | */ |
||
105 | public function findContent(Query $query, array $languageFilter = array(), $filterOnUserPermissions = true) |
||
122 | |||
123 | /** |
||
124 | * Finds contentInfo objects for the given query. |
||
125 | * |
||
126 | * @see SearchServiceInterface::findContentInfo() |
||
127 | * |
||
128 | * @since 5.4.5 |
||
129 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if query is not valid |
||
130 | * |
||
131 | * @param \eZ\Publish\API\Repository\Values\Content\Query $query |
||
132 | * @param array $languageFilter - a map of filters for the returned fields. |
||
133 | * Currently supports: <code>array("languages" => array(<language1>,..), "useAlwaysAvailable" => bool)</code> |
||
134 | * useAlwaysAvailable defaults to true to avoid exceptions on missing translations. |
||
135 | * @param bool $filterOnUserPermissions if true (default) only the objects which is the user allowed to read are returned. |
||
136 | * |
||
137 | * @return \eZ\Publish\API\Repository\Values\Content\Search\SearchResult |
||
138 | */ |
||
139 | public function findContentInfo(Query $query, array $languageFilter = array(), $filterOnUserPermissions = true) |
||
150 | |||
151 | /** |
||
152 | * Finds SPI content info objects for the given query. |
||
153 | * |
||
154 | * Internal for use by {@link findContent} and {@link findContentInfo}. |
||
155 | * |
||
156 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if query is not valid |
||
157 | * |
||
158 | * @param \eZ\Publish\API\Repository\Values\Content\Query $query |
||
159 | * @param array $languageFilter - a map of filters for the returned fields. |
||
160 | * Currently supports: <code>array("languages" => array(<language1>,..), "useAlwaysAvailable" => bool)</code> |
||
161 | * useAlwaysAvailable defaults to true to avoid exceptions on missing translations. |
||
162 | * @param bool $filterOnUserPermissions if true only the objects which is the user allowed to read are returned. |
||
163 | * |
||
164 | * @return \eZ\Publish\API\Repository\Values\Content\Search\SearchResult With "raw" SPI contentInfo objects in result |
||
165 | */ |
||
166 | protected function internalFindContentInfo(Query $query, array $languageFilter = array(), $filterOnUserPermissions = true) |
||
197 | |||
198 | /** |
||
199 | * Checks that $criteria does not contain Location criterions. |
||
200 | * |
||
201 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException |
||
202 | * |
||
203 | * @param \eZ\Publish\API\Repository\Values\Content\Query\Criterion[] $criteria |
||
204 | * @param string $argumentName |
||
205 | */ |
||
206 | protected function validateContentCriteria(array $criteria, $argumentName) |
||
220 | |||
221 | /** |
||
222 | * Checks that $query does not contain Location sort clauses. |
||
223 | * |
||
224 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException |
||
225 | * |
||
226 | * @param \eZ\Publish\API\Repository\Values\Content\Query $query |
||
227 | */ |
||
228 | protected function validateContentSortClauses(Query $query) |
||
236 | |||
237 | /** |
||
238 | * Performs a query for a single content object. |
||
239 | * |
||
240 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException if the object was not found by the query or due to permissions |
||
241 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if criterion is not valid |
||
242 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if there is more than one result matching the criterions |
||
243 | * |
||
244 | * @param \eZ\Publish\API\Repository\Values\Content\Query\Criterion $filter |
||
245 | * @param array $languageFilter Configuration for specifying prioritized languages query will be performed on. |
||
246 | * Currently supports: <code>array("languages" => array(<language1>,..), "useAlwaysAvailable" => bool)</code> |
||
247 | * useAlwaysAvailable defaults to true to avoid exceptions on missing translations. |
||
248 | * @param bool $filterOnUserPermissions if true only the objects which is the user allowed to read are returned. |
||
249 | * |
||
250 | * @return \eZ\Publish\API\Repository\Values\Content\Content |
||
251 | */ |
||
252 | public function findSingle(Criterion $filter, array $languageFilter = array(), $filterOnUserPermissions = true) |
||
270 | |||
271 | /** |
||
272 | * Suggests a list of values for the given prefix. |
||
273 | * |
||
274 | * @param string $prefix |
||
275 | * @param string[] $fieldPaths |
||
276 | * @param int $limit |
||
277 | * @param \eZ\Publish\API\Repository\Values\Content\Query\Criterion $filter |
||
278 | */ |
||
279 | public function suggest($prefix, $fieldPaths = array(), $limit = 10, Criterion $filter = null) |
||
282 | |||
283 | /** |
||
284 | * Finds Locations for the given query. |
||
285 | * |
||
286 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if query is not valid |
||
287 | * |
||
288 | * @param \eZ\Publish\API\Repository\Values\Content\LocationQuery $query |
||
289 | * @param array $languageFilter Configuration for specifying prioritized languages query will be performed on. |
||
290 | * Currently supports: <code>array("languages" => array(<language1>,..), "useAlwaysAvailable" => bool)</code> |
||
291 | * useAlwaysAvailable defaults to true to avoid exceptions on missing translations |
||
292 | * @param bool $filterOnUserPermissions if true only the objects which is the user allowed to read are returned. |
||
293 | * |
||
294 | * @return \eZ\Publish\API\Repository\Values\Content\Search\SearchResult |
||
295 | */ |
||
296 | public function findLocations(LocationQuery $query, array $languageFilter = array(), $filterOnUserPermissions = true) |
||
331 | |||
332 | /** |
||
333 | * Get SortClause objects built from $location's sort options. |
||
334 | * |
||
335 | * @param \eZ\Publish\API\Repository\Values\Content\Location $location |
||
336 | * |
||
337 | * @return \eZ\Publish\API\Repository\Values\Content\Query\SortClause[] |
||
338 | */ |
||
339 | public function getSortClauseFromLocation(Location $location) |
||
343 | } |
||
344 |
This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.