Completed
Push — master ( d5645f...b278b8 )
by
unknown
01:20
created

RepeatOrders_OrderFormAddressExtension   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 34
Duplicated Lines 52.94 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 4
dl 18
loc 34
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A updateOrderFormAddress() 0 9 1
A saveAddressAndSkipSubscriptionStep() 9 9 1
A saveAddressAndCreateSubscription() 9 9 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
4
class RepeatOrders_OrderFormAddressExtension extends Extension
5
{
6
7
    public function updateOrderFormAddress(&$form)
8
    {
9
        $nextButton = new FormAction('saveAddressAndSkipSubscriptionStep', 'Confirm and Pay');
10
        $nextButton->addExtraClass('next');
11
        $subsButton = new FormAction('saveAddressAndCreateSubscription', 'Create Subscription');
12
        $subsButton->addExtraClass('next');
13
        $actions = FieldList::create($subsButton, $nextButton);
14
        $form->setActions($actions);
15
    }
16
17
18 View Code Duplication
    public function saveAddressAndSkipSubscriptionStep(array $data, Form $form, SS_HTTPRequest $request)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
19
    {
20
        $this->owner->saveAddressDetails($data, $form, $request);
21
22
        $nextStepLink = CheckoutPage::find_next_step_link('orderformsubscription');
23
        $this->owner->controller->redirect($nextStepLink);
0 ignored issues
show
Bug introduced by
The property controller does not seem to exist in SS_Object.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
24
25
        return true;
26
    }
27
28 View Code Duplication
    public function saveAddressAndCreateSubscription(array $data, Form $form, SS_HTTPRequest $request)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
29
    {
30
        $this->owner->saveAddressDetails($data, $form, $request);
31
32
        $nextStepLink = CheckoutPage::find_next_step_link('orderformaddress');
33
        $this->owner->controller->redirect($nextStepLink);
0 ignored issues
show
Bug introduced by
The property controller does not seem to exist in SS_Object.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
34
35
        return true;
36
    }
37
}
38