Completed
Push — ezp-30616-follow-up ( 40e8e4...b42e6a )
by Łukasz
17:13
created

ObjectStateEventSubscriber   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 26
Duplicated Lines 61.54 %

Coupling/Cohesion

Components 1
Dependencies 8

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 8
dl 16
loc 26
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getSubscribedEvents() 0 6 1
A onSetContentState() 16 16 2

How to fix   Duplicated Code   

Duplicated Code

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
2
3
/**
4
 * @copyright Copyright (C) eZ Systems AS. All rights reserved.
5
 * @license For full copyright and license information view LICENSE file distributed with this source code.
6
 */
7
namespace eZ\Publish\Core\Search\Common\EventSubscriber;
8
9
use eZ\Publish\API\Repository\Events\ObjectState\SetContentStateEvent;
10
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
11
12
class ObjectStateEventSubscriber extends AbstractSearchEventSubscriber implements EventSubscriberInterface
13
{
14
    public static function getSubscribedEvents(): array
15
    {
16
        return [
17
            SetContentStateEvent::class => 'onSetContentState',
18
        ];
19
    }
20
21 View Code Duplication
    public function onSetContentState(SetContentStateEvent $event)
22
    {
23
        $contentInfo = $this->persistenceHandler->contentHandler()->loadContentInfo($event->getContentInfo()->id);
24
25
        $this->searchHandler->indexContent(
26
            $this->persistenceHandler->contentHandler()->load(
27
                $contentInfo->id,
28
                $contentInfo->currentVersionNo
29
            )
30
        );
31
32
        $locations = $this->persistenceHandler->locationHandler()->loadLocationsByContent($contentInfo->id);
33
        foreach ($locations as $location) {
34
            $this->searchHandler->indexLocation($location);
35
        }
36
    }
37
}
38