PathSubscriber   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 5
Bugs 2 Features 0
Metric Value
c 5
b 2
f 0
dl 0
loc 42
wmc 4
lcom 1
cbo 3
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getSubscribedEvents() 0 6 1
A handleHydrate() 0 13 2
1
<?php
2
3
/*
4
 * This file is part of Sulu.
5
 *
6
 * (c) MASSIVE ART WebServices GmbH
7
 *
8
 * This source file is subject to the MIT license that is bundled
9
 * with this source code in the file LICENSE.
10
 */
11
12
namespace Sulu\Component\DocumentManager\Subscriber\Behavior\Mapping;
13
14
use Sulu\Component\DocumentManager\Behavior\Mapping\PathBehavior;
15
use Sulu\Component\DocumentManager\DocumentInspector;
16
use Sulu\Component\DocumentManager\Event\HydrateEvent;
17
use Sulu\Component\DocumentManager\Events;
18
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
19
20
/**
21
 * Set the path on the document.
22
 */
23
class PathSubscriber implements EventSubscriberInterface
24
{
25
    /**
26
     * @var DocumentInspector
27
     */
28
    private $documentInspector;
29
30
    /**
31
     * @param DocumentInspector $documentInspector
32
     */
33
    public function __construct(DocumentInspector $documentInspector)
34
    {
35
        $this->documentInspector = $documentInspector;
36
    }
37
38
    /**
39
     * {@inheritdoc}
40
     */
41
    public static function getSubscribedEvents()
42
    {
43
        return [
44
            Events::HYDRATE => 'handleHydrate',
45
        ];
46
    }
47
48
    /**
49
     * @param HydrateEvent $event
50
     */
51
    public function handleHydrate(HydrateEvent $event)
52
    {
53
        $document = $event->getDocument();
54
55
        if (!$document instanceof PathBehavior) {
56
            return;
57
        }
58
59
        $event->getAccessor()->set(
60
            'path',
61
            $this->documentInspector->getPath($document)
62
        );
63
    }
64
}
65