PaymentMethodExtractor   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A extractPaymentMethod() 0 13 3
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\Service;
9
10
use Generated\Shared\Transfer\QuoteTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfer\QuoteTransfer was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
11
use SprykerEco\Zed\Ratepay\Business\Exception\NoPaymentMethodException;
12
13
class PaymentMethodExtractor implements PaymentMethodExtractorInterface
14
{
15
    /**
16
     * @var array
17
     */
18
    protected $paymentMethodsMapping;
19
20
    /**
21
     * @param array $paymentMethodsMapping
22
     */
23
    public function __construct(array $paymentMethodsMapping)
24
    {
25
        $this->paymentMethodsMapping = $paymentMethodsMapping;
26
    }
27
28
    /**
29
     * @param \Generated\Shared\Transfer\QuoteTransfer $quoteTransfer
30
     *
31
     * @throws \SprykerEco\Zed\Ratepay\Business\Exception\NoPaymentMethodException
32
     *
33
     * @return \Spryker\Shared\Kernel\Transfer\AbstractTransfer|null
34
     */
35
    public function extractPaymentMethod(QuoteTransfer $quoteTransfer)
36
    {
37
        if (!$quoteTransfer->getPayment()) {
38
            return null;
39
        }
40
        $payment = $quoteTransfer->getPayment();
41
        $paymentMethodName = $payment->getPaymentMethod();
42
        if (!isset($this->paymentMethodsMapping[$paymentMethodName])) {
43
            throw new NoPaymentMethodException();
44
        }
45
        $paymentMethodGet = 'get' . ucfirst($this->paymentMethodsMapping[$paymentMethodName]);
46
47
        return $payment->$paymentMethodGet();
48
    }
49
}
50