NotificationHandler   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 11
dl 0
loc 25
ccs 0
cts 11
cp 0
rs 10
c 2
b 0
f 0
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A SendNotification() 0 15 3
1
<?php
2
3
namespace garethp\ews;
4
5
use garethp\ews\API\Enumeration\SubscriptionStatusType;
6
use garethp\ews\API\Exception;
7
use garethp\ews\API\ExchangeWebServices;
8
use garethp\ews\API\Message\SendNotificationResponseMessageType;
9
use garethp\ews\API\Message\SendNotificationResponseType;
10
use garethp\ews\API\Message\SendNotificationResultType;
11
12
class NotificationHandler
13
{
14
    private $handler;
15
16
    public function __construct(callable $handler)
17
    {
18
        $this->handler = $handler;
19
    }
20
21
    // @codingStandardsIgnoreLine
22
    public function SendNotification(SendNotificationResponseType $message)
23
    {
24
        $message = ExchangeWebServices::drillDownResponseLevels($message);
25
26
        $handler = $this->handler;
27
        $response = $handler($message);
28
29
        if ($response !== SubscriptionStatusType::OK && $response !== SubscriptionStatusType::UNSUBSCRIBE) {
30
            throw new Exception('Unexpected Subscription Status Response');
31
        }
32
33
        $result = new SendNotificationResultType();
34
        $result->setSubscriptionStatus($response);
35
36
        return $result->toXmlObject();
37
    }
38
}
39