MoveEvent::getDocument()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
c 2
b 0
f 1
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
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
class MoveEvent extends AbstractEvent
15
{
16
    /**
17
     * @var object
18
     */
19
    private $document;
20
21
    /**
22
     * @var string
23
     */
24
    private $destId;
25
26
    /**
27
     * @var string
28
     */
29
    private $destName;
30
31
    /**
32
     * @param object $document
33
     * @param string $destId
34
     */
35
    public function __construct($document, $destId)
36
    {
37
        $this->document = $document;
38
        $this->destId = $destId;
39
    }
40
41
    /**
42
     * {@inheritdoc}
43
     */
44
    public function getDebugMessage()
45
    {
46
        return sprintf(
47
            'd:%s did:%s, dnam:%s',
48
            $this->document ? spl_object_hash($this->document) : '<no document>',
49
            $this->destId ?: '<no dest>',
50
            $this->destName ?: '<no dest name>'
51
        );
52
    }
53
54
    /**
55
     * @return object
56
     */
57
    public function getDocument()
58
    {
59
        return $this->document;
60
    }
61
62
    /**
63
     * @return string
64
     */
65
    public function getDestId()
66
    {
67
        return $this->destId;
68
    }
69
70
    /**
71
     * @param string $name
72
     */
73
    public function setDestName($name)
74
    {
75
        $this->destName = $name;
76
    }
77
78
    /**
79
     * @return bool
80
     */
81
    public function hasDestName()
82
    {
83
        return null !== $this->destName;
84
    }
85
86
    /**
87
     * @return string
88
     *
89
     * @throws \RuntimeException
90
     */
91
    public function getDestName()
92
    {
93
        if (!$this->destName) {
94
            throw new \RuntimeException(sprintf(
95
                'No destName set in copy/move event when copying/moving document "%s" to "%s". ' .
96
                'This should have been set by a listener',
97
                spl_object_hash($this->document),
98
                $this->destId
99
            ));
100
        }
101
102
        return $this->destName;
103
    }
104
}
105