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 |
||
29 | class SearchService implements SearchServiceInterface |
||
30 | { |
||
31 | /** |
||
32 | * @var \eZ\Publish\Core\Repository\Repository |
||
33 | */ |
||
34 | protected $repository; |
||
35 | |||
36 | /** |
||
37 | * @var \eZ\Publish\SPI\Search\Handler |
||
38 | */ |
||
39 | protected $searchHandler; |
||
40 | |||
41 | /** |
||
42 | * @var array |
||
43 | */ |
||
44 | protected $settings; |
||
45 | |||
46 | /** |
||
47 | * @var \eZ\Publish\Core\Repository\Helper\DomainMapper |
||
48 | */ |
||
49 | protected $domainMapper; |
||
50 | |||
51 | /** |
||
52 | * @var \eZ\Publish\Core\Repository\PermissionsCriterionHandler |
||
53 | */ |
||
54 | protected $permissionsCriterionHandler; |
||
55 | |||
56 | /** |
||
57 | * Setups service with reference to repository object that created it & corresponding handler. |
||
58 | * |
||
59 | * @param \eZ\Publish\API\Repository\Repository $repository |
||
60 | * @param \eZ\Publish\SPI\Search\Handler $searchHandler |
||
61 | * @param \eZ\Publish\Core\Repository\Helper\DomainMapper $domainMapper |
||
62 | * @param \eZ\Publish\Core\Repository\PermissionsCriterionHandler $permissionsCriterionHandler |
||
63 | * @param array $settings |
||
64 | */ |
||
65 | View Code Duplication | public function __construct( |
|
81 | |||
82 | /** |
||
83 | * Finds content objects for the given query. |
||
84 | * |
||
85 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if query is not valid |
||
86 | * |
||
87 | * @param \eZ\Publish\API\Repository\Values\Content\Query $query |
||
88 | * @param array $languageFilter Configuration for specifying prioritized languages query will be performed on. |
||
89 | * Currently supports: <code>array("languages" => array(<language1>,..), "useAlwaysAvailable" => bool)</code> |
||
90 | * useAlwaysAvailable defaults to true to avoid exceptions on missing translations. |
||
91 | * @param bool $filterOnUserPermissions if true only the objects which the user is allowed to read are returned. |
||
92 | * |
||
93 | * @return \eZ\Publish\API\Repository\Values\Content\Search\SearchResult |
||
94 | */ |
||
95 | public function findContent(Query $query, array $languageFilter = array(), $filterOnUserPermissions = true) |
||
112 | |||
113 | /** |
||
114 | * Finds contentInfo objects for the given query. |
||
115 | * |
||
116 | * @see SearchServiceInterface::findContentInfo() |
||
117 | * |
||
118 | * @since 5.4.5 |
||
119 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if query is not valid |
||
120 | * |
||
121 | * @param \eZ\Publish\API\Repository\Values\Content\Query $query |
||
122 | * @param array $languageFilter - a map of filters for the returned fields. |
||
123 | * Currently supports: <code>array("languages" => array(<language1>,..), "useAlwaysAvailable" => bool)</code> |
||
124 | * useAlwaysAvailable defaults to true to avoid exceptions on missing translations. |
||
125 | * @param bool $filterOnUserPermissions if true (default) only the objects which is the user allowed to read are returned. |
||
126 | * |
||
127 | * @return \eZ\Publish\API\Repository\Values\Content\Search\SearchResult |
||
128 | */ |
||
129 | public function findContentInfo(Query $query, array $languageFilter = array(), $filterOnUserPermissions = true) |
||
140 | |||
141 | /** |
||
142 | * Finds SPI content info objects for the given query. |
||
143 | * |
||
144 | * Internal for use by {@link findContent} and {@link findContentInfo}. |
||
145 | * |
||
146 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if query is not valid |
||
147 | * |
||
148 | * @param \eZ\Publish\API\Repository\Values\Content\Query $query |
||
149 | * @param array $languageFilter - a map of filters for the returned fields. |
||
150 | * Currently supports: <code>array("languages" => array(<language1>,..), "useAlwaysAvailable" => bool)</code> |
||
151 | * useAlwaysAvailable defaults to true to avoid exceptions on missing translations. |
||
152 | * @param bool $filterOnUserPermissions if true only the objects which is the user allowed to read are returned. |
||
153 | * |
||
154 | * @return \eZ\Publish\API\Repository\Values\Content\Search\SearchResult With "raw" SPI contentInfo objects in result |
||
155 | */ |
||
156 | protected function internalFindContentInfo(Query $query, array $languageFilter = array(), $filterOnUserPermissions = true) |
||
187 | |||
188 | /** |
||
189 | * Checks that $criteria does not contain Location criterions. |
||
190 | * |
||
191 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException |
||
192 | * |
||
193 | * @param \eZ\Publish\API\Repository\Values\Content\Query\Criterion[] $criteria |
||
194 | * @param string $argumentName |
||
195 | */ |
||
196 | protected function validateContentCriteria(array $criteria, $argumentName) |
||
210 | |||
211 | /** |
||
212 | * Checks that $query does not contain Location sort clauses. |
||
213 | * |
||
214 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException |
||
215 | * |
||
216 | * @param \eZ\Publish\API\Repository\Values\Content\Query $query |
||
217 | */ |
||
218 | protected function validateContentSortClauses(Query $query) |
||
226 | |||
227 | /** |
||
228 | * Performs a query for a single content object. |
||
229 | * |
||
230 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException if the object was not found by the query or due to permissions |
||
231 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if criterion is not valid |
||
232 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if there is more than one result matching the criterions |
||
233 | * |
||
234 | * @param \eZ\Publish\API\Repository\Values\Content\Query\Criterion $filter |
||
235 | * @param array $languageFilter Configuration for specifying prioritized languages query will be performed on. |
||
236 | * Currently supports: <code>array("languages" => array(<language1>,..), "useAlwaysAvailable" => bool)</code> |
||
237 | * useAlwaysAvailable defaults to true to avoid exceptions on missing translations. |
||
238 | * @param bool $filterOnUserPermissions if true only the objects which is the user allowed to read are returned. |
||
239 | * |
||
240 | * @return \eZ\Publish\API\Repository\Values\Content\Content |
||
241 | */ |
||
242 | public function findSingle(Criterion $filter, array $languageFilter = array(), $filterOnUserPermissions = true) |
||
260 | |||
261 | /** |
||
262 | * Suggests a list of values for the given prefix. |
||
263 | * |
||
264 | * @param string $prefix |
||
265 | * @param string[] $fieldPaths |
||
266 | * @param int $limit |
||
267 | * @param \eZ\Publish\API\Repository\Values\Content\Query\Criterion $filter |
||
268 | */ |
||
269 | public function suggest($prefix, $fieldPaths = array(), $limit = 10, Criterion $filter = null) |
||
272 | |||
273 | /** |
||
274 | * Finds Locations for the given query. |
||
275 | * |
||
276 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if query is not valid |
||
277 | * |
||
278 | * @param \eZ\Publish\API\Repository\Values\Content\LocationQuery $query |
||
279 | * @param array $languageFilter Configuration for specifying prioritized languages query will be performed on. |
||
280 | * Currently supports: <code>array("languages" => array(<language1>,..), "useAlwaysAvailable" => bool)</code> |
||
281 | * useAlwaysAvailable defaults to true to avoid exceptions on missing translations |
||
282 | * @param bool $filterOnUserPermissions if true only the objects which is the user allowed to read are returned. |
||
283 | * |
||
284 | * @return \eZ\Publish\API\Repository\Values\Content\Search\SearchResult |
||
285 | */ |
||
286 | public function findLocations(LocationQuery $query, array $languageFilter = array(), $filterOnUserPermissions = true) |
||
321 | |||
322 | public function supports($capabilityFlag) |
||
330 | } |
||
331 |
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a given class or a super-class is assigned to a property that is type hinted more strictly.
Either this assignment is in error or an instanceof check should be added for that assignment.