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 |
||
| 28 | class ObjectState extends RestController |
||
| 29 | { |
||
| 30 | /** |
||
| 31 | * ObjectState service. |
||
| 32 | * |
||
| 33 | * @var \eZ\Publish\API\Repository\ObjectStateService |
||
| 34 | */ |
||
| 35 | protected $objectStateService; |
||
| 36 | |||
| 37 | /** |
||
| 38 | * Content service. |
||
| 39 | * |
||
| 40 | * @var \eZ\Publish\API\Repository\ContentService |
||
| 41 | */ |
||
| 42 | protected $contentService; |
||
| 43 | |||
| 44 | /** |
||
| 45 | * Construct controller. |
||
| 46 | * |
||
| 47 | * @param \eZ\Publish\API\Repository\ObjectStateService $objectStateService |
||
| 48 | * @param \eZ\Publish\API\Repository\ContentService $contentService |
||
| 49 | */ |
||
| 50 | public function __construct(ObjectStateService $objectStateService, ContentService $contentService) |
||
| 55 | |||
| 56 | /** |
||
| 57 | * Creates a new object state group. |
||
| 58 | * |
||
| 59 | * @throws \eZ\Publish\Core\REST\Server\Exceptions\ForbiddenException |
||
| 60 | * |
||
| 61 | * @return \eZ\Publish\Core\REST\Server\Values\CreatedObjectStateGroup |
||
| 62 | */ |
||
| 63 | View Code Duplication | public function createObjectStateGroup(Request $request) |
|
| 84 | |||
| 85 | /** |
||
| 86 | * Creates a new object state. |
||
| 87 | * |
||
| 88 | * @param $objectStateGroupId |
||
| 89 | * |
||
| 90 | * @throws \eZ\Publish\Core\REST\Server\Exceptions\ForbiddenException |
||
| 91 | * |
||
| 92 | * @return \eZ\Publish\Core\REST\Server\Values\CreatedObjectState |
||
| 93 | */ |
||
| 94 | public function createObjectState($objectStateGroupId, Request $request) |
||
| 121 | |||
| 122 | /** |
||
| 123 | * Loads an object state group. |
||
| 124 | * |
||
| 125 | * @param $objectStateGroupId |
||
| 126 | * |
||
| 127 | * @return \eZ\Publish\API\Repository\Values\ObjectState\ObjectStateGroup |
||
| 128 | */ |
||
| 129 | public function loadObjectStateGroup($objectStateGroupId) |
||
| 133 | |||
| 134 | /** |
||
| 135 | * Loads an object state. |
||
| 136 | * |
||
| 137 | * @param $objectStateGroupId |
||
| 138 | * @param $objectStateId |
||
| 139 | * |
||
| 140 | * @return \eZ\Publish\Core\REST\Common\Values\RestObjectState |
||
| 141 | */ |
||
| 142 | public function loadObjectState($objectStateGroupId, $objectStateId) |
||
| 149 | |||
| 150 | /** |
||
| 151 | * Returns a list of all object state groups. |
||
| 152 | * |
||
| 153 | * @return \eZ\Publish\Core\REST\Server\Values\ObjectStateGroupList |
||
| 154 | */ |
||
| 155 | public function loadObjectStateGroups() |
||
| 161 | |||
| 162 | /** |
||
| 163 | * Returns a list of all object states of the given group. |
||
| 164 | * |
||
| 165 | * @param $objectStateGroupId |
||
| 166 | * |
||
| 167 | * @return \eZ\Publish\Core\REST\Server\Values\ObjectStateList |
||
| 168 | */ |
||
| 169 | public function loadObjectStates($objectStateGroupId) |
||
| 178 | |||
| 179 | /** |
||
| 180 | * The given object state group including the object states is deleted. |
||
| 181 | * |
||
| 182 | * @param $objectStateGroupId |
||
| 183 | * |
||
| 184 | * @return \eZ\Publish\Core\REST\Server\Values\NoContent |
||
| 185 | */ |
||
| 186 | public function deleteObjectStateGroup($objectStateGroupId) |
||
| 194 | |||
| 195 | /** |
||
| 196 | * The given object state is deleted. |
||
| 197 | * |
||
| 198 | * @param $objectStateId |
||
| 199 | * |
||
| 200 | * @return \eZ\Publish\Core\REST\Server\Values\NoContent |
||
| 201 | */ |
||
| 202 | public function deleteObjectState($objectStateId) |
||
| 210 | |||
| 211 | /** |
||
| 212 | * Updates an object state group. |
||
| 213 | * |
||
| 214 | * @param $objectStateGroupId |
||
| 215 | * |
||
| 216 | * @throws \eZ\Publish\Core\REST\Server\Exceptions\ForbiddenException |
||
| 217 | * |
||
| 218 | * @return \eZ\Publish\API\Repository\Values\ObjectState\ObjectStateGroup |
||
| 219 | */ |
||
| 220 | View Code Duplication | public function updateObjectStateGroup($objectStateGroupId, Request $request) |
|
| 239 | |||
| 240 | /** |
||
| 241 | * Updates an object state. |
||
| 242 | * |
||
| 243 | * @param $objectStateGroupId |
||
| 244 | * @param $objectStateId |
||
| 245 | * |
||
| 246 | * @throws \eZ\Publish\Core\REST\Server\Exceptions\ForbiddenException |
||
| 247 | * |
||
| 248 | * @return \eZ\Publish\Core\REST\Common\Values\RestObjectState |
||
| 249 | */ |
||
| 250 | View Code Duplication | public function updateObjectState($objectStateGroupId, $objectStateId, Request $request) |
|
| 269 | |||
| 270 | /** |
||
| 271 | * Returns the object states of content. |
||
| 272 | * |
||
| 273 | * @param $contentId |
||
| 274 | * |
||
| 275 | * @return \eZ\Publish\Core\REST\Common\Values\ContentObjectStates |
||
| 276 | */ |
||
| 277 | public function getObjectStatesForContent($contentId) |
||
| 295 | |||
| 296 | /** |
||
| 297 | * Updates object states of content |
||
| 298 | * An object state in the input overrides the state of the object state group. |
||
| 299 | * |
||
| 300 | * @param $contentId |
||
| 301 | * |
||
| 302 | * @throws \eZ\Publish\Core\REST\Server\Exceptions\ForbiddenException |
||
| 303 | * |
||
| 304 | * @return \eZ\Publish\Core\REST\Common\Values\ContentObjectStates |
||
| 305 | */ |
||
| 306 | public function setObjectStatesForContent($contentId, Request $request) |
||
| 342 | } |
||
| 343 |
This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.
Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.