Completed
Push — master ( b435f2...2b3f9c )
by Jason
29s
created

FlexSlider::updateCMSFields()   B

Complexity

Conditions 4
Paths 5

Size

Total Lines 29
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 20
CRAP Score 4.128

Importance

Changes 17
Bugs 1 Features 1
Metric Value
c 17
b 1
f 1
dl 0
loc 29
ccs 20
cts 25
cp 0.8
rs 8.5806
cc 4
eloc 19
nc 5
nop 1
crap 4.128
1
<?php
2
3
class FlexSlider extends DataExtension
4
{
5
    public static $db = array(
6
        'Animation' => "Enum('slide, fade', 'slide')",
7
        'Loop' => 'Boolean',
8
        'Animate' => 'Boolean',
9
        'ThumbnailNav' => 'Boolean',
10
    );
11
12
    public static $has_many = array(
13
        'Slides' => 'SlideImage',
14
    );
15
16
    public static $defaults = array(
17
        'Loop' => '1',
18
        'Animate' => '1',
19
    );
20
21 3
    public function populateDefaults()
22
    {
23 3
        parent::populateDefaults();
24 3
        $this->Loop = 1;
0 ignored issues
show
Bug introduced by
The property Loop does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
25 3
        $this->Animate = 1;
0 ignored issues
show
Bug introduced by
The property Animate does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
26 3
    }
27
28 1
    public function updateCMSFields(FieldList $fields)
29
    {
30
        // Slides
31 1
        if ($this->owner->ID) {
32 1
            $config = GridFieldConfig_RecordEditor::create();
33 1
            if (class_exists('GridFieldSortableRows')) {
34
                $config->addComponent(new GridFieldSortableRows('SortOrder'));
35
            }
36 1
            if (class_exists('GridFieldBulkUpload')) {
37
                $config->addComponent(new GridFieldBulkUpload());
38
                $config->addComponent(new GridFieldBulkManager());
39
            }
40 1
            $config->removeComponentsByType('GridFieldAddExistingAutocompleter');
41 1
            $config->removeComponentsByType('GridFieldDeleteAction');
42 1
            $config->addComponent(new GridFieldDeleteAction(false));
43 1
            $SlidesField = GridField::create('Slides', 'Slides', $this->owner->Slides()->sort('SortOrder'), $config);
44
45 1
            $fields->addFieldsToTab('Root.Slides', array(
46 1
                HeaderField::create('SliderHD', 'Slides', 3),
47 1
                $SlidesField,
48 1
                ToggleCompositeField::create('ConfigHD', 'Slider Settings', array(
49 1
                    CheckboxField::create('Animate', 'Animate automatically'),
50 1
                    DropdownField::create('Animation', 'Animation option', $this->owner->dbObject('Animation')->enumValues()),
51 1
                    CheckboxField::create('Loop', 'Loop the carousel'),
52
                    //CheckboxField::create('ThumbnailNav', 'Thumbnail Navigation'),
0 ignored issues
show
Unused Code Comprehensibility introduced by
70% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
53 1
                )),
54 1
            ));
55 1
        }
56 1
    }
57
58 1
    public function SlideShow()
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
59
    {
60 1
        return $this->owner->Slides()->filter(array('ShowSlide' => 1))->sort('SortOrder');
61
    }
62
}
63