Passed
Push — feature/paypal-express ( bc349b...5b8ae4 )
by Volodymyr
04:37
created

isPaymenMethodBraintreePayPalExpressSelected()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 1
nc 2
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
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 && !$this->isPaymenMethodBraintreePayPalExpressSelected($quoteTransfer)) {
29
                continue;
30
            }
31
            $result->append($paymentMethod);
32
        }
33
34
        $paymentMethodsTransfer->setMethods($result);
35
36
        return $paymentMethodsTransfer;
37
    }
38
39
    /**
40
     * @param \Generated\Shared\Transfer\QuoteTransfer $quoteTransfer
41
     *
42
     * @return bool
43
     */
44
    protected function isPaymenMethodBraintreePayPalExpressSelected(QuoteTransfer $quoteTransfer): bool
45
    {
46
        return $quoteTransfer->getPayment() && $quoteTransfer->getPayment()->getPaymentSelection() === BraintreeConfig::PAYMENT_METHOD_PAY_PAL_EXPRESS;
47
    }
48
}
49