Code Duplication    Length = 44-48 lines in 2 locations

eZ/Publish/Core/Repository/ObjectStateService.php 2 locations

@@ 185-228 (lines=44) @@
182
     *
183
     * @return \eZ\Publish\API\Repository\Values\ObjectState\ObjectStateGroup
184
     */
185
    public function updateObjectStateGroup(APIObjectStateGroup $objectStateGroup, ObjectStateGroupUpdateStruct $objectStateGroupUpdateStruct)
186
    {
187
        if ($this->repository->hasAccess('state', 'administrate') !== true) {
188
            throw new UnauthorizedException('state', 'administrate');
189
        }
190
191
        $loadedObjectStateGroup = $this->loadObjectStateGroup($objectStateGroup->id);
192
193
        $inputStruct = $this->buildObjectStateGroupUpdateInputStruct(
194
            $loadedObjectStateGroup,
195
            $objectStateGroupUpdateStruct->identifier,
196
            $objectStateGroupUpdateStruct->defaultLanguageCode,
197
            $objectStateGroupUpdateStruct->names,
198
            $objectStateGroupUpdateStruct->descriptions
199
        );
200
201
        if ($objectStateGroupUpdateStruct->identifier !== null) {
202
            try {
203
                $existingObjectStateGroup = $this->objectStateHandler->loadGroupByIdentifier($inputStruct->identifier);
204
                if ($existingObjectStateGroup->id != $loadedObjectStateGroup->id) {
205
                    throw new InvalidArgumentException(
206
                        'objectStateGroupUpdateStruct',
207
                        'Object state group with provided identifier already exists'
208
                    );
209
                }
210
            } catch (APINotFoundException $e) {
211
                // Do nothing
212
            }
213
        }
214
215
        $this->repository->beginTransaction();
216
        try {
217
            $spiObjectStateGroup = $this->objectStateHandler->updateGroup(
218
                $loadedObjectStateGroup->id,
219
                $inputStruct
220
            );
221
            $this->repository->commit();
222
        } catch (Exception $e) {
223
            $this->repository->rollback();
224
            throw $e;
225
        }
226
227
        return $this->buildDomainObjectStateGroupObject($spiObjectStateGroup);
228
    }
229
230
    /**
231
     * Deletes a object state group including all states and links to content.
@@ 343-390 (lines=48) @@
340
     *
341
     * @return \eZ\Publish\API\Repository\Values\ObjectState\ObjectState
342
     */
343
    public function updateObjectState(APIObjectState $objectState, ObjectStateUpdateStruct $objectStateUpdateStruct)
344
    {
345
        if ($this->repository->hasAccess('state', 'administrate') !== true) {
346
            throw new UnauthorizedException('state', 'administrate');
347
        }
348
349
        $loadedObjectState = $this->loadObjectState($objectState->id);
350
351
        $inputStruct = $this->buildObjectStateUpdateInputStruct(
352
            $loadedObjectState,
353
            $objectStateUpdateStruct->identifier,
354
            $objectStateUpdateStruct->defaultLanguageCode,
355
            $objectStateUpdateStruct->names,
356
            $objectStateUpdateStruct->descriptions
357
        );
358
359
        if ($objectStateUpdateStruct->identifier !== null) {
360
            try {
361
                $existingObjectState = $this->objectStateHandler->loadByIdentifier(
362
                    $inputStruct->identifier,
363
                    $loadedObjectState->getObjectStateGroup()->id
364
                );
365
366
                if ($existingObjectState->id != $loadedObjectState->id) {
367
                    throw new InvalidArgumentException(
368
                        'objectStateUpdateStruct',
369
                        'Object state with provided identifier already exists in provided object state group'
370
                    );
371
                }
372
            } catch (APINotFoundException $e) {
373
                // Do nothing
374
            }
375
        }
376
377
        $this->repository->beginTransaction();
378
        try {
379
            $spiObjectState = $this->objectStateHandler->update(
380
                $loadedObjectState->id,
381
                $inputStruct
382
            );
383
            $this->repository->commit();
384
        } catch (Exception $e) {
385
            $this->repository->rollback();
386
            throw $e;
387
        }
388
389
        return $this->buildDomainObjectStateObject($spiObjectState);
390
    }
391
392
    /**
393
     * Changes the priority of the state.