PaymentMethod   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 21
dl 0
loc 48
rs 10
c 0
b 0
f 0
wmc 6

5 Methods

Rating   Name   Duplication   Size   Complexity  
A SelectedPaymentMethod() 0 3 1
A setpaymentmethod() 0 4 1
A checkoutconfig() 0 6 1
A paymentmethod() 0 8 2
A PaymentMethodForm() 0 11 1
1
<?php
2
3
namespace SilverShop\Checkout\Step;
4
5
use SilverShop\Cart\ShoppingCart;
6
use SilverShop\Checkout\Checkout;
7
use SilverShop\Checkout\CheckoutComponentConfig;
8
use SilverShop\Checkout\Component\Payment;
9
use SilverShop\Forms\CheckoutForm;
10
use SilverStripe\Forms\FieldList;
11
use SilverStripe\Forms\FormAction;
12
use SilverStripe\Omnipay\GatewayInfo;
13
14
class PaymentMethod extends CheckoutStep
15
{
16
    private static $allowed_actions = [
0 ignored issues
show
introduced by
The private property $allowed_actions is not used, and could be removed.
Loading history...
17
        'paymentmethod',
18
        'PaymentMethodForm',
19
    ];
20
21
    protected function checkoutconfig()
22
    {
23
        $config = CheckoutComponentConfig::create(ShoppingCart::curr(), false);
24
        $config->addComponent(Payment::create());
25
26
        return $config;
27
    }
28
29
    public function paymentmethod()
30
    {
31
        $gateways = GatewayInfo::getSupportedGateways();
32
        if (count($gateways) == 1) {
33
            return $this->owner->redirect($this->NextStepLink());
34
        }
35
        return [
36
            'OrderForm' => $this->PaymentMethodForm(),
37
        ];
38
    }
39
40
    public function PaymentMethodForm()
41
    {
42
        $form = CheckoutForm::create($this->owner, 'PaymentMethodForm', $this->checkoutconfig());
43
        $form->setActions(
44
            FieldList::create(
45
                FormAction::create('setpaymentmethod', _t('SilverShop\Checkout\Step\CheckoutStep.Continue', 'Continue'))
46
            )
47
        );
48
        $this->owner->extend('updatePaymentMethodForm', $form);
49
50
        return $form;
51
    }
52
53
    public function setpaymentmethod($data, $form)
0 ignored issues
show
Unused Code introduced by
The parameter $data is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

53
    public function setpaymentmethod(/** @scrutinizer ignore-unused */ $data, $form)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
54
    {
55
        $this->checkoutconfig()->setData($form->getData());
56
        return $this->owner->redirect($this->NextStepLink());
57
    }
58
59
    public function SelectedPaymentMethod()
60
    {
61
        return Checkout::get($this->owner->Cart())->getSelectedPaymentMethod(true);
62
    }
63
}
64