Completed
Push — master ( 36de4f...1487f5 )
by Nicolaas
01:22
created

CallToActionPageExtension::updateCMSFields()   B

Complexity

Conditions 2
Paths 2

Size

Total Lines 25
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 25
rs 8.8571
c 0
b 0
f 0
cc 2
eloc 17
nc 2
nop 1
1
<?php
2
3
/**
4
 *@author nicolaas [at] sunnysideup.co.nz
5
 *
6
 *
7
 **/
8
9
class CallToActionPageExtension extends DataExtension
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
10
{
11
    private static $has_one = [
0 ignored issues
show
Unused Code introduced by
The property $has_one is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
12
        'CallToAction' => 'CallToAction'
13
    ];
14
15
    private static $field_labels = [
0 ignored issues
show
Unused Code introduced by
The property $field_labels is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
16
        'CallToAction' => 'Call to action'
17
    ];
18
19
    private static $field_labels_right = [
0 ignored issues
show
Unused Code introduced by
The property $field_labels_right is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
20
        'CallToAction' => 'Big image with optional text'
21
    ];
22
23
    public function updateCMSFields(FieldList $fields)
24
    {
25
        $fieldLabels = $this->owner->FieldLabels();
0 ignored issues
show
Unused Code introduced by
$fieldLabels 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...
26
        $fieldLabelsRight = Config::inst()->get('CallToActionPageExtension', 'field_labels_right');
0 ignored issues
show
Unused Code introduced by
$fieldLabelsRight 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...
27
        $tabTitle = _t('CallToActionPageExtension.CALL_TO_ACTION', 'Call to Action');
28
        $link = '/admin/calltoaction/';
29
        if($this->owner->CallToActionID) {
30
            $link = $this->owner->CallToAction()->CMSEditLink();
31
        }
32
        $fields->addFieldsToTab(
33
            'Root.'.$tabTitle,
34
            [
35
                DropdownField::create(
36
                    'CallToActionID',
37
                    $tabTitle,
38
                    [0 => _t('CallToActionPageExtension', '-- please select --')] +CallToAction::get()->map()->toArray()
39
                ),
40
                LiteralField::create(
41
                    'CallToActionEdit',
42
                    '<h2><a href="'.$link.'">✎ '.$tabTitle.'</a><h2>'
43
                )
44
            ]
45
        );
46
        return $fields;
47
    }
48
}
49