Notifications::setUrl()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
/*
4
 * This file is part of the XabbuhPandaClient package.
5
 *
6
 * (c) Christian Flothmann <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Xabbuh\PandaClient\Model;
13
14
/**
15
 * Representation of notification as they are returned by the Panda encoding
16
 * service api.
17
 *
18
 * @author Christian Flothmann <[email protected]>
19
 */
20
class Notifications implements ModelInterface
21
{
22
    private $url;
23
24
    private $events;
25
26
    public function getUrl()
27
    {
28
        return $this->url;
29
    }
30
31
    public function setUrl($url)
32
    {
33
        $this->url = $url;
34
    }
35
36
    public function addNotificationEvent(NotificationEvent $event)
37
    {
38
        $this->events[$event->getEvent()] = $event;
39
    }
40
41
    public function removeNotificationEvent(NotificationEvent $event)
42
    {
43
        if (isset($this->events[$event->getEvent()])) {
44
            unset($this->events[$event->getEvent()]);
45
        }
46
    }
47
48
    public function hasNotificationEvent($eventName)
49
    {
50
        // normalise the event name
51
        $eventName = strtr($eventName, '_', '-');
52
53
        return isset($this->events[$eventName]);
54
    }
55
56
    /**
57
     * @param string $eventName
58
     *
59
     * @return NotificationEvent
60
     *
61
     * @throws \InvalidArgumentException
62
     */
63
    public function getNotificationEvent($eventName)
64
    {
65
        // normalise the event name
66
        $eventName = strtr($eventName, '_', '-');
67
        if ($this->hasNotificationEvent($eventName)) {
68
            return $this->events[$eventName];
69
        } else {
70
            throw new \InvalidArgumentException('Event '.$eventName.' is not registered');
71
        }
72
    }
73
}
74