CountryPrice_OrderStepDOD   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A updateCMSFields() 0 36 1
1
<?php
2
3
/**
4
 * Adds individual country messages
5
 * for ordersteps
6
 *
7
 */
8
9
class CountryPrice_OrderStepDOD extends DataExtension
10
{
11
    private static $db = array(
12
        'SendEmailToDistributor' => 'Boolean'
13
    );
14
15
    private static $has_many = array(
16
        'EcommerceOrderStepCountryDatas' => 'EcommerceOrderStepCountryData',
17
    );
18
19
    private static $field_labels = array(
20
        'EcommerceOrderStepCountryDatas' => 'Regionalisation',
21
    );
22
23
    /**
24
     * Update Fields
25
     * @return FieldList
0 ignored issues
show
Documentation introduced by
Should the return type not be FieldList|null?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
26
     */
27
    public function updateCMSFields(FieldList $fields)
28
    {
29
        $owner = $this->owner;
0 ignored issues
show
Unused Code introduced by
$owner is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
30
        $bccExplanation = _t(
31
            'CountryPrice_OrderStepDOD.BCC_EXPLANATION',
32
            '
33
                E-mails during this step (if any) will be copied to distributor?
34
                <br />These emails can be customised.
35
        '
36
        );
37
        $gridField = $fields->dataFieldByName('EcommerceOrderStepCountryDatas');
38
        $fields->removeFieldFromTab(
39
            'Root.EcommerceOrderStepCountryDatas',
40
            'EcommerceOrderStepCountryDatas'
41
        );
42
        $fields->addFieldsToTab(
43
            'Root.EcommerceOrderStepCountryDatas',
44
            array(
45
                CheckboxField::create(
46
                    'SendEmailToDistributor',
47
                    _t('CountryPrice_OrderStepDOD.SEND_EMAIL_TO_DISTRIBUTOR', 'BCC to Distributor')
48
                )->setDescription(
49
                    $bccExplanation
50
                ),
51
            )
52
        );
53
        $customisation = _t(
54
            'CountryPrice_OrderStepDOD.CUSTOMISATION_PER_COUNTRY',
55
            'Customisation per country'
56
        );
57
        $gridField->setTitle($customisation);
58
        $fields->addFieldsToTab(
59
            'Root.EcommerceOrderStepCountryDatas',
60
            $gridField
0 ignored issues
show
Documentation introduced by
$gridField is of type object<FormField>, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
61
        );
62
    }
63
}
64