NotificationHandler::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 2
rs 10
c 1
b 0
f 0
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