Completed
Push — feature/EVO-7278-security-and-... ( 0e0414 )
by
unknown
13:20
created

ModelEvent   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 149
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 11
lcom 1
cbo 2
dl 0
loc 149
ccs 0
cts 44
cp 0
rs 10
c 0
b 0
f 0

10 Methods

Rating   Name   Duplication   Size   Complexity  
A setActionByDispatchName() 0 8 2
A getAction() 0 4 1
A getCollectionId() 0 4 1
A setCollectionId() 0 4 1
A getCollectionName() 0 4 1
A setCollectionName() 0 4 1
A getCollectionClass() 0 4 1
A setCollectionClass() 0 4 1
A getCollection() 0 4 1
A setCollection() 0 4 1
1
<?php
2
/**
3
 * Event for Model collection changes
4
 */
5
6
namespace Graviton\RestBundle\Event;
7
8
use Symfony\Component\Config\Definition\Exception\Exception;
9
use Symfony\Component\EventDispatcher\Event;
10
11
/**
12
 * Event that is passed to graviton.rest.event listeners
13
 *
14
 * @author   List of contributors <https://github.com/libgraviton/graviton/graphs/contributors>
15
 * @license  http://opensource.org/licenses/gpl-license.php GNU Public License
16
 * @link     http://swisscom.ch
17
 */
18
class ModelEvent extends Event
19
{
20
    /** EVENT: Insert a new Document */
21
    const MODEL_EVENT_INSERT = 'document.model.event.insert';
22
23
    /** EVENT: Update a new Document */
24
    const MODEL_EVENT_UPDATE = 'document.model.event.update';
25
26
    /** EVENT: Delete a new Document */
27
    const MODEL_EVENT_DELETE = 'document.model.event.delete';
28
29
    /**
30
     * @var array list with event names
31
     */
32
    private $availableEvents = [
33
        self::MODEL_EVENT_INSERT => 'insert',
34
        self::MODEL_EVENT_UPDATE => 'update',
35
        self::MODEL_EVENT_DELETE => 'delete'
36
    ];
37
38
    /**
39
     * Containing operation executed
40
     * update or insert
41
     *
42
     * @var string
43
     */
44
    private $action;
45
46
    /**
47
     * Containing the ID of the Model on which the change happened
48
     *
49
     * @var string
50
     */
51
    private $collectionId;
52
53
    /**
54
     * Containing the name of the Collection affected
55
     *
56
     * @var string
57
     */
58
    private $collectionName;
59
60
    /**
61
     * Containing the name of the Collection affected
62
     *
63
     * @var string
64
     */
65
    private $collectionClass;
66
67
    /**
68
     * Containing the changed object collection
69
     *
70
     * @var Object
71
     */
72
    private $collection;
73
74
    /**
75
     * Set the event ACTION name based on the fired name
76
     *
77
     * @param string $dispatchName the CONST value for dispatch names
78
     *
79
     * @return string
0 ignored issues
show
Documentation introduced by
Should the return type not be string|null?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
80
     * @throws Exception
81
     */
82
    public function setActionByDispatchName($dispatchName)
83
    {
84
        if (array_key_exists($dispatchName, $this->availableEvents)) {
85
            $this->action = $this->availableEvents[$dispatchName];
86
        } else {
87
            throw new Exception('Document Model event dispatch type not found: ' . $dispatchName);
88
        }
89
    }
90
91
    /**
92
     * @return string
93
     */
94
    public function getAction()
95
    {
96
        return $this->action;
97
    }
98
99
    /**
100
     * @return string Collection ID
101
     */
102
    public function getCollectionId()
103
    {
104
        return $this->collectionId;
105
    }
106
107
    /**
108
     * @param string $collectionId Collection ID
109
     * @return void
110
     */
111
    public function setCollectionId($collectionId)
112
    {
113
        $this->collectionId = $collectionId;
114
    }
115
116
    /**
117
     * @return string
118
     */
119
    public function getCollectionName()
120
    {
121
        return $this->collectionName;
122
    }
123
124
    /**
125
     * @param string $collectionName Name to Be
126
     * @return void
127
     */
128
    public function setCollectionName($collectionName)
129
    {
130
        $this->collectionName = $collectionName;
131
    }
132
133
    /**
134
     * @return string
135
     */
136
    public function getCollectionClass()
137
    {
138
        return $this->collectionClass;
139
    }
140
141
    /**
142
     * @param string $collectionClass Collection Class
143
     * @return void
144
     */
145
    public function setCollectionClass($collectionClass)
146
    {
147
        $this->collectionClass = $collectionClass;
148
    }
149
150
    /**
151
     * @return Object
152
     */
153
    public function getCollection()
154
    {
155
        return $this->collection;
156
    }
157
158
    /**
159
     * @param Object $collection Collection Object
160
     * @return void
161
     */
162
    public function setCollection($collection)
163
    {
164
        $this->collection = $collection;
165
    }
166
}
167