TransactionHandlerAbstract   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 75
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 15
c 1
b 0
f 0
dl 0
loc 75
rs 10
wmc 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A sendRequest() 0 3 1
A getMethodMapper() 0 7 2
A __construct() 0 8 1
A registerMethodMapper() 0 3 1
1
<?php
2
3
/**
4
 * MIT License
5
 * Use of this software requires acceptance of the Evaluation License Agreement. See LICENSE file.
6
 */
7
8
namespace SprykerEco\Zed\Ratepay\Business\Request;
9
10
use SprykerEco\Zed\Ratepay\Business\Api\Adapter\AdapterInterface;
11
use SprykerEco\Zed\Ratepay\Business\Api\Converter\ConverterFactoryInterface;
12
use SprykerEco\Zed\Ratepay\Business\Api\Model\Response\BaseResponse;
13
use SprykerEco\Zed\Ratepay\Business\Exception\NoMethodMapperException;
14
use SprykerEco\Zed\Ratepay\Business\Log\LoggerTrait;
15
use SprykerEco\Zed\Ratepay\Persistence\RatepayQueryContainerInterface;
16
17
abstract class TransactionHandlerAbstract implements TransactionHandlerInterface
18
{
19
    use LoggerTrait;
20
21
    public const TRANSACTION_TYPE = null;
22
23
    /**
24
     * @var \SprykerEco\Zed\Ratepay\Business\Api\Adapter\AdapterInterface
25
     */
26
    protected $executionAdapter;
27
28
    /**
29
     * @var \SprykerEco\Zed\Ratepay\Business\Api\Converter\ConverterFactoryInterface
30
     */
31
    protected $converterFactory;
32
33
    /**
34
     * @var \SprykerEco\Zed\Ratepay\Persistence\RatepayQueryContainerInterface $queryContainer
35
     */
36
    protected $queryContainer;
37
38
    /**
39
     * @var array
40
     */
41
    protected $methodMappers = [];
42
43
    /**
44
     * @param \SprykerEco\Zed\Ratepay\Business\Api\Adapter\AdapterInterface $executionAdapter
45
     * @param \SprykerEco\Zed\Ratepay\Business\Api\Converter\ConverterFactoryInterface $converterFactory
46
     * @param \SprykerEco\Zed\Ratepay\Persistence\RatepayQueryContainerInterface $queryContainer
47
     */
48
    public function __construct(
49
        AdapterInterface $executionAdapter,
50
        ConverterFactoryInterface $converterFactory,
51
        RatepayQueryContainerInterface $queryContainer
52
    ) {
53
        $this->executionAdapter = $executionAdapter;
54
        $this->converterFactory = $converterFactory;
55
        $this->queryContainer = $queryContainer;
56
    }
57
58
    /**
59
     * @param string $request
60
     *
61
     * @return \SprykerEco\Zed\Ratepay\Business\Api\Model\Response\BaseResponse
62
     */
63
    protected function sendRequest($request)
64
    {
65
        return new BaseResponse($this->executionAdapter->sendRequest($request));
66
    }
67
68
    /**
69
     * @param \SprykerEco\Zed\Ratepay\Business\Request\RequestMethodInterface $mapper
70
     *
71
     * @return void
72
     */
73
    public function registerMethodMapper(RequestMethodInterface $mapper)
74
    {
75
        $this->methodMappers[$mapper->getMethodName()] = $mapper;
76
    }
77
78
    /**
79
     * @param string $method
80
     *
81
     * @throws \SprykerEco\Zed\Ratepay\Business\Exception\NoMethodMapperException
82
     *
83
     * @return \SprykerEco\Zed\Ratepay\Business\Request\Payment\Method\MethodInterface|\SprykerEco\Zed\Ratepay\Business\Request\Service\Method\MethodInterface
84
     */
85
    protected function getMethodMapper($method)
86
    {
87
        if (isset($this->methodMappers[$method]) === false) {
88
            throw new NoMethodMapperException(sprintf("The method %s mapper is not registered.", $method));
89
        }
90
91
        return $this->methodMappers[$method];
92
    }
93
}
94