PaypalExpressPaymentMethodFilter   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A filterPaymentMethods() 0 16 4
A isPaymenMethodBraintreePayPalExpressSelected() 0 4 2
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\Braintree\Business\Payment\Filter;
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\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...
13
use SprykerEco\Shared\Braintree\BraintreeConfig;
14
15
class PaypalExpressPaymentMethodFilter implements PaypalExpressPaymentMethodFilterInterface
16
{
17
    /**
18
     * @param \Generated\Shared\Transfer\PaymentMethodsTransfer $paymentMethodsTransfer
19
     * @param \Generated\Shared\Transfer\QuoteTransfer $quoteTransfer
20
     *
21
     * @return \Generated\Shared\Transfer\PaymentMethodsTransfer
22
     */
23
    public function filterPaymentMethods(PaymentMethodsTransfer $paymentMethodsTransfer, QuoteTransfer $quoteTransfer): PaymentMethodsTransfer
24
    {
25
        $result = new ArrayObject();
26
27
        foreach ($paymentMethodsTransfer->getMethods() as $paymentMethod) {
28
            if ($paymentMethod->getMethodName() === BraintreeConfig::PAYMENT_METHOD_PAY_PAL_EXPRESS
29
                && !$this->isPaymenMethodBraintreePayPalExpressSelected($quoteTransfer)
30
            ) {
31
                continue;
32
            }
33
            $result->append($paymentMethod);
34
        }
35
36
        $paymentMethodsTransfer->setMethods($result);
37
38
        return $paymentMethodsTransfer;
39
    }
40
41
    /**
42
     * @param \Generated\Shared\Transfer\QuoteTransfer $quoteTransfer
43
     *
44
     * @return bool
45
     */
46
    protected function isPaymenMethodBraintreePayPalExpressSelected(QuoteTransfer $quoteTransfer): bool
47
    {
48
        return $quoteTransfer->getPayment()
49
            && $quoteTransfer->getPayment()->getPaymentSelection() === BraintreeConfig::PAYMENT_METHOD_PAY_PAL_EXPRESS;
50
    }
51
}
52