HandlerManager   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 9
c 1
b 0
f 0
dl 0
loc 37
rs 10
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A forwardMessage() 0 5 2
A registerHandler() 0 4 1
A __construct() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Cakasim\Payone\Sdk\Notification\Handler;
6
7
use Cakasim\Payone\Sdk\Notification\Context\ContextInterface;
8
use Psr\Log\LoggerInterface;
9
10
/**
11
 * Implementation of the HandlerManagerInterface.
12
 *
13
 * @author Fabian Böttcher <[email protected]>
14
 * @since 0.1.0
15
 */
16
class HandlerManager implements HandlerManagerInterface
17
{
18
    /**
19
     * @var LoggerInterface The SDK logger.
20
     */
21
    protected $logger;
22
23
    /**
24
     * @var HandlerInterface[] The notification handlers.
25
     */
26
    protected $handlers = [];
27
28
    /**
29
     * @param LoggerInterface $logger The SDK logger.
30
     */
31
    public function __construct(LoggerInterface $logger)
32
    {
33
        $this->logger = $logger;
34
    }
35
36
    /**
37
     * @inheritDoc
38
     */
39
    public function registerHandler(HandlerInterface $handler): void
40
    {
41
        $this->logger->info(sprintf("Register PAYONE notification message handler '%s'.", get_class($handler)));
42
        $this->handlers[] = $handler;
43
    }
44
45
    /**
46
     * @inheritDoc
47
     */
48
    public function forwardMessage(ContextInterface $context): void
49
    {
50
        foreach ($this->handlers as $handler) {
51
            $this->logger->info(sprintf("Forward PAYONE notification message to handler '%s'.", get_class($handler)));
52
            $handler->handleNotification($context);
53
        }
54
    }
55
}
56