AbstractMappingEvent   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 93
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 7
Bugs 0 Features 3
Metric Value
c 7
b 0
f 3
dl 0
loc 93
wmc 11
lcom 1
cbo 3
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A getDebugMessage() 0 9 4
A getNode() 0 4 1
A getDocument() 0 4 1
A getLocale() 0 4 1
A getAccessor() 0 10 2
A hasDocument() 0 4 1
A hasNode() 0 4 1
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\Event;
13
14
use PHPCR\NodeInterface;
15
use Sulu\Component\DocumentManager\DocumentAccessor;
16
17
abstract class AbstractMappingEvent extends AbstractEvent
18
{
19
    use EventOptionsTrait;
20
21
    /**
22
     * @var object
23
     */
24
    protected $document;
25
26
    /**
27
     * @var string
28
     */
29
    protected $locale;
30
31
    /**
32
     * @var NodeInterface
33
     */
34
    protected $node;
35
36
    /**
37
     * @var DocumentAccessor
38
     */
39
    protected $accessor;
40
41
    /**
42
     * {@inheritdoc}
43
     */
44
    public function getDebugMessage()
45
    {
46
        return sprintf(
47
            'n:%s d:%s l:%s',
48
            $this->node ? $this->node->getPath() : '<no node>',
49
            $this->document ? spl_object_hash($this->document) : '<no document>',
50
            $this->locale ?: '<no locale>'
51
        );
52
    }
53
54
    /**
55
     * @return NodeInterface
56
     */
57
    public function getNode()
58
    {
59
        return $this->node;
60
    }
61
62
    /**
63
     * @return object
64
     */
65
    public function getDocument()
66
    {
67
        return $this->document;
68
    }
69
70
    /**
71
     * @return string
72
     */
73
    public function getLocale()
74
    {
75
        return $this->locale;
76
    }
77
78
    /**
79
     * TODO: Refactor this away.
80
     *
81
     * @return DocumentAccessor
82
     */
83
    public function getAccessor()
84
    {
85
        if ($this->accessor) {
86
            return $this->accessor;
87
        }
88
89
        $this->accessor = new DocumentAccessor($this->getDocument());
90
91
        return $this->accessor;
92
    }
93
94
    /**
95
     * Return true if the document has been set.
96
     */
97
    public function hasDocument()
98
    {
99
        return null !== $this->document;
100
    }
101
102
    /**
103
     * @return bool
104
     */
105
    public function hasNode()
106
    {
107
        return null !== $this->node;
108
    }
109
}
110