PaymentMethodFilter::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
/**
4
 * MIT License
5
 * For full license information, please view the LICENSE file that was distributed with this source code.
6
 */
7
8
namespace SprykerEco\Zed\Easycredit\Business\Payment;
9
10
use ArrayObject;
11
use Generated\Shared\Transfer\PaymentMethodsTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfer\PaymentMethodsTransfer 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...
12
use Generated\Shared\Transfer\PaymentMethodTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfer\PaymentMethodTransfer 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...
13
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...
14
use SprykerEco\Zed\Easycredit\EasycreditConfig;
15
16
class PaymentMethodFilter implements PaymentMethodFilterInterface
17
{
18
    /**
19
     * @var \SprykerEco\Zed\Easycredit\EasycreditConfig
20
     */
21
    protected $config;
22
23
    /**
24
     * @param \SprykerEco\Zed\Easycredit\EasycreditConfig $config
25
     */
26
    public function __construct(EasycreditConfig $config)
27
    {
28
        $this->config = $config;
29
    }
30
31
    /**
32
     * @param \Generated\Shared\Transfer\PaymentMethodsTransfer $paymentMethodsTransfer
33
     * @param \Generated\Shared\Transfer\QuoteTransfer $quoteTransfer
34
     *
35
     * @return \Generated\Shared\Transfer\PaymentMethodsTransfer
36
     */
37
    public function filterPaymentMethods(PaymentMethodsTransfer $paymentMethodsTransfer, QuoteTransfer $quoteTransfer): PaymentMethodsTransfer
38
    {
39
        $result = new ArrayObject();
40
41
        foreach ($paymentMethodsTransfer->getMethods() as $paymentMethod) {
42
            if ($this->isPaymentMethodEasycredit($paymentMethod) && !$this->isAvailable($quoteTransfer)) {
43
                continue;
44
            }
45
            $result->append($paymentMethod);
46
        }
47
48
        $paymentMethodsTransfer->setMethods($result);
49
50
        return $paymentMethodsTransfer;
51
    }
52
53
    /**
54
     * @param \Generated\Shared\Transfer\QuoteTransfer $quoteTransfer
55
     *
56
     * @return bool
57
     */
58
    protected function isAvailable(QuoteTransfer $quoteTransfer): bool
59
    {
60
        return $quoteTransfer->getTotals()->getGrandTotal() >= $this->config->getPaymentMethodMinAvailableMoneyValue() &&
61
            $quoteTransfer->getTotals()->getGrandTotal() <= $this->config->getPaymentMethodMaxAvailableMoneyValue() ||
62
            ($quoteTransfer->getBillingAddress() && in_array($quoteTransfer->getBillingAddress()->getIso2Code(), $this->config->getPaymentMethodAvailableCountries()));
63
    }
64
65
    /**
66
     * @param \Generated\Shared\Transfer\PaymentMethodTransfer $paymentMethodTransfer
67
     *
68
     * @return bool
69
     */
70
    protected function isPaymentMethodEasycredit(PaymentMethodTransfer $paymentMethodTransfer): bool
71
    {
72
        return strpos($paymentMethodTransfer->getMethodName(), $this->config->getPaymentMethod()) !== false;
73
    }
74
}
75