Completed
Push — ezp-30646 ( 6400c7...ee4911 )
by
unknown
21:35
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
dl 16
loc 26
rs 10
c 0
b 0
f 0
wmc 3
lcom 1
cbo 8

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
namespace eZ\Publish\Core\Search\Common\EventSubscriber;
4
5
use eZ\Publish\Core\Event\ObjectState\ObjectStateEvents;
6
use eZ\Publish\Core\Event\ObjectState\SetContentStateEvent;
7
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
8
9
class ObjectStateEventSubscriber extends AbstractSearchEventSubscriber implements EventSubscriberInterface
10
{
11
    public static function getSubscribedEvents(): array
12
    {
13
        return [
14
            ObjectStateEvents::SET_CONTENT_STATE => 'onSetContentState',
15
        ];
16
    }
17
18 View Code Duplication
    public function onSetContentState(SetContentStateEvent $event)
19
    {
20
        $contentInfo = $this->persistenceHandler->contentHandler()->loadContentInfo($event->getContentInfo()->id);
21
22
        $this->searchHandler->indexContent(
23
            $this->persistenceHandler->contentHandler()->load(
24
                $contentInfo->id,
25
                $contentInfo->currentVersionNo
26
            )
27
        );
28
29
        $locations = $this->persistenceHandler->locationHandler()->loadLocationsByContent($contentInfo->id);
30
        foreach ($locations as $location) {
31
            $this->searchHandler->indexLocation($location);
32
        }
33
    }
34
}