Completed
Push — master ( 2af8a7...e05d39 )
by Gareth
05:52 queued 15s
created

NotificationHandler::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 4
rs 10
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
    public function SendNotification(SendNotificationResponseType $message)
22
    {
23
        $message = ExchangeWebServices::drillDownResponseLevels($message);
24
25
        $handler = $this->handler;
26
        $response = $handler($message);
27
28
        if ($response !== SubscriptionStatusType::OK && $response !== SubscriptionStatusType::UNSUBSCRIBE) {
29
            throw new Exception('Unexpected Subscription Status Response');
30
        }
31
32
        $result = new SendNotificationResultType();
33
        $result->setSubscriptionStatus($response);
34
35
        return $result->toXmlObject();
36
    }
37
}