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 |
||
| 34 | class SearchService implements SearchServiceInterface |
||
| 35 | { |
||
| 36 | /** @var \eZ\Publish\Core\Repository\Repository */ |
||
| 37 | protected $repository; |
||
| 38 | |||
| 39 | /** @var \eZ\Publish\SPI\Search\Handler */ |
||
| 40 | protected $searchHandler; |
||
| 41 | |||
| 42 | /** @var array */ |
||
| 43 | protected $settings; |
||
| 44 | |||
| 45 | /** @var \eZ\Publish\Core\Repository\Mapper\ContentDomainMapper */ |
||
| 46 | protected $contentDomainMapper; |
||
| 47 | |||
| 48 | /** @var \eZ\Publish\API\Repository\PermissionCriterionResolver */ |
||
| 49 | protected $permissionCriterionResolver; |
||
| 50 | |||
| 51 | /** @var \eZ\Publish\Core\Search\Common\BackgroundIndexer */ |
||
| 52 | protected $backgroundIndexer; |
||
| 53 | |||
| 54 | /** |
||
| 55 | * Setups service with reference to repository object that created it & corresponding handler. |
||
| 56 | * |
||
| 57 | * @param \eZ\Publish\API\Repository\Repository $repository |
||
| 58 | * @param \eZ\Publish\SPI\Search\Handler $searchHandler |
||
| 59 | * @param \eZ\Publish\Core\Repository\Mapper\ContentDomainMapper $contentDomainMapper |
||
| 60 | * @param \eZ\Publish\API\Repository\PermissionCriterionResolver $permissionCriterionResolver |
||
| 61 | * @param \eZ\Publish\Core\Search\Common\BackgroundIndexer $backgroundIndexer |
||
| 62 | * @param array $settings |
||
| 63 | */ |
||
| 64 | View Code Duplication | public function __construct( |
|
| 82 | |||
| 83 | /** |
||
| 84 | * Finds content objects for the given query. |
||
| 85 | * |
||
| 86 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if query is not valid |
||
| 87 | * |
||
| 88 | * @param \eZ\Publish\API\Repository\Values\Content\Query $query |
||
| 89 | * @param array $languageFilter Configuration for specifying prioritized languages query will be performed on. |
||
| 90 | * Currently supports: <code>array("languages" => array(<language1>,..), "useAlwaysAvailable" => bool)</code> |
||
| 91 | * useAlwaysAvailable defaults to true to avoid exceptions on missing translations. |
||
| 92 | * @param bool $filterOnUserPermissions if true only the objects which the user is allowed to read are returned. |
||
| 93 | * |
||
| 94 | * @return \eZ\Publish\API\Repository\Values\Content\Search\SearchResult |
||
| 95 | */ |
||
| 96 | public function findContent(Query $query, array $languageFilter = [], bool $filterOnUserPermissions = true): SearchResult |
||
| 106 | |||
| 107 | /** |
||
| 108 | * Finds contentInfo objects for the given query. |
||
| 109 | * |
||
| 110 | * @see SearchServiceInterface::findContentInfo() |
||
| 111 | * |
||
| 112 | * @since 5.4.5 |
||
| 113 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if query is not valid |
||
| 114 | * |
||
| 115 | * @param \eZ\Publish\API\Repository\Values\Content\Query $query |
||
| 116 | * @param array $languageFilter - a map of filters for the returned fields. |
||
| 117 | * Currently supports: <code>array("languages" => array(<language1>,..), "useAlwaysAvailable" => bool)</code> |
||
| 118 | * useAlwaysAvailable defaults to true to avoid exceptions on missing translations. |
||
| 119 | * @param bool $filterOnUserPermissions if true (default) only the objects which is the user allowed to read are returned. |
||
| 120 | * |
||
| 121 | * @return \eZ\Publish\API\Repository\Values\Content\Search\SearchResult |
||
| 122 | */ |
||
| 123 | public function findContentInfo(Query $query, array $languageFilter = [], bool $filterOnUserPermissions = true): SearchResult |
||
| 134 | |||
| 135 | /** |
||
| 136 | * Finds SPI content info objects for the given query. |
||
| 137 | * |
||
| 138 | * Internal for use by {@link findContent} and {@link findContentInfo}. |
||
| 139 | * |
||
| 140 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if query is not valid |
||
| 141 | * |
||
| 142 | * @param \eZ\Publish\API\Repository\Values\Content\Query $query |
||
| 143 | * @param array $languageFilter - a map of filters for the returned fields. |
||
| 144 | * Currently supports: <code>array("languages" => array(<language1>,..), "useAlwaysAvailable" => bool)</code> |
||
| 145 | * useAlwaysAvailable defaults to true to avoid exceptions on missing translations. |
||
| 146 | * @param bool $filterOnUserPermissions if true only the objects which is the user allowed to read are returned. |
||
| 147 | * |
||
| 148 | * @return \eZ\Publish\API\Repository\Values\Content\Search\SearchResult With "raw" SPI contentInfo objects in result |
||
| 149 | */ |
||
| 150 | protected function internalFindContentInfo(Query $query, array $languageFilter = [], $filterOnUserPermissions = true) |
||
| 181 | |||
| 182 | /** |
||
| 183 | * Checks that $criteria does not contain Location criterions. |
||
| 184 | * |
||
| 185 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException |
||
| 186 | * |
||
| 187 | * @param \eZ\Publish\API\Repository\Values\Content\Query\Criterion[] $criteria |
||
| 188 | * @param string $argumentName |
||
| 189 | */ |
||
| 190 | protected function validateContentCriteria(array $criteria, $argumentName) |
||
| 204 | |||
| 205 | /** |
||
| 206 | * Checks that $query does not contain Location sort clauses. |
||
| 207 | * |
||
| 208 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException |
||
| 209 | * |
||
| 210 | * @param \eZ\Publish\API\Repository\Values\Content\Query $query |
||
| 211 | */ |
||
| 212 | protected function validateContentSortClauses(Query $query) |
||
| 220 | |||
| 221 | /** |
||
| 222 | * Performs a query for a single content object. |
||
| 223 | * |
||
| 224 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException if the object was not found by the query or due to permissions |
||
| 225 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if criterion is not valid |
||
| 226 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if there is more than one result matching the criterions |
||
| 227 | * |
||
| 228 | * @param \eZ\Publish\API\Repository\Values\Content\Query\Criterion $filter |
||
| 229 | * @param array $languageFilter Configuration for specifying prioritized languages query will be performed on. |
||
| 230 | * Currently supports: <code>array("languages" => array(<language1>,..), "useAlwaysAvailable" => bool)</code> |
||
| 231 | * useAlwaysAvailable defaults to true to avoid exceptions on missing translations. |
||
| 232 | * @param bool $filterOnUserPermissions if true only the objects which is the user allowed to read are returned. |
||
| 233 | * |
||
| 234 | * @return \eZ\Publish\API\Repository\Values\Content\Content |
||
| 235 | */ |
||
| 236 | public function findSingle(Criterion $filter, array $languageFilter = [], bool $filterOnUserPermissions = true): Content |
||
| 254 | |||
| 255 | /** |
||
| 256 | * Suggests a list of values for the given prefix. |
||
| 257 | * |
||
| 258 | * @param string $prefix |
||
| 259 | * @param string[] $fieldPaths |
||
| 260 | * @param int $limit |
||
| 261 | * @param \eZ\Publish\API\Repository\Values\Content\Query\Criterion $filter |
||
| 262 | */ |
||
| 263 | public function suggest(string $prefix, array $fieldPaths = [], int $limit = 10, Criterion $filter = null) |
||
| 266 | |||
| 267 | /** |
||
| 268 | * Finds Locations for the given query. |
||
| 269 | * |
||
| 270 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if query is not valid |
||
| 271 | * |
||
| 272 | * @param \eZ\Publish\API\Repository\Values\Content\LocationQuery $query |
||
| 273 | * @param array $languageFilter Configuration for specifying prioritized languages query will be performed on. |
||
| 274 | * Currently supports: <code>array("languages" => array(<language1>,..), "useAlwaysAvailable" => bool)</code> |
||
| 275 | * useAlwaysAvailable defaults to true to avoid exceptions on missing translations |
||
| 276 | * @param bool $filterOnUserPermissions if true only the objects which is the user allowed to read are returned. |
||
| 277 | * |
||
| 278 | * @return \eZ\Publish\API\Repository\Values\Content\Search\SearchResult |
||
| 279 | */ |
||
| 280 | public function findLocations(LocationQuery $query, array $languageFilter = [], bool $filterOnUserPermissions = true): SearchResult |
||
| 314 | |||
| 315 | /** |
||
| 316 | * Adds content, read Permission criteria if needed and return false if no access at all. |
||
| 317 | * |
||
| 318 | * @uses \eZ\Publish\API\Repository\PermissionCriterionResolver::getPermissionsCriterion() |
||
| 319 | * |
||
| 320 | * @param \eZ\Publish\API\Repository\Values\Content\Query\Criterion $criterion |
||
| 321 | * |
||
| 322 | * @return bool|\eZ\Publish\API\Repository\Values\Content\Query\Criterion |
||
| 323 | */ |
||
| 324 | View Code Duplication | protected function addPermissionsCriterion(Criterion &$criterion) |
|
| 345 | |||
| 346 | public function supports(int $capabilityFlag): bool |
||
| 354 | } |
||
| 355 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..