Completed
Push — master ( 0470fe...7a7bdf )
by Jason
7s
created

AccordionBlock::getPanelList()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2.032

Importance

Changes 0
Metric Value
dl 0
loc 7
ccs 4
cts 5
cp 0.8
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 0
crap 2.032
1
<?php
2
3
class AccordionBlock extends Block
4
{
5
    /**
6
     * @var string
7
     */
8
    private static $singular_name = 'Accordion Block';
9
10
    /**
11
     * @var string
12
     */
13
    private static $plural_name = 'Accordion Blocks';
14
15
    /**
16
     * @var array
17
     */
18
    private static $db = array(
19
        'Content' => 'HTMLText',
20
        'SortOrder' => 'Int',
21
    );
22
23
    /**
24
     * @var array
25
     */
26
    private static $has_many = array(
27
        'Panels' => 'AccordionPanel',
28
    );
29
30
    /**
31
     * @return FieldList
32
     */
33 1 View Code Duplication
    public function getCMSFields()
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...
34
    {
35 1
        $fields = parent::getCMSFields();
36
37 1
        $fields->removeByName(array(
38 1
            'SortOrder',
39 1
            'Panels',
40 1
        ));
41
42 1
        $config = GridFieldConfig_RecordEditor::create();
43 1
        if (class_exists('GridFieldOrderableRows')) {
44 1
            $config->addComponent(new GridFieldOrderableRows());
45 1
        }
46 1
        $config->removeComponentsByType('GridFieldAddExistingAutocompleter');
47 1
        $config->removeComponentsByType('GridFieldDeleteAction');
48 1
        $config->addComponent(new GridFieldDeleteAction(false));
49
50 1
        if ($this->ID) {
51 1
            $fields->addFieldsToTab('Root.Panels', array(
52 1
                GridField::create('Panels', 'Accordion Panels', $this->Panels()->sort('Sort'), $config),
0 ignored issues
show
Documentation Bug introduced by
The method Panels does not exist on object<AccordionBlock>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
53 1
            ));
54 1
        }
55
56 1
        return $fields;
57
    }
58
59
    /**
60
     * @return DataList
61
     */
62 1
    public function getPanelList()
63
    {
64 1
        if ($this->Panels()->exists()) {
0 ignored issues
show
Documentation Bug introduced by
The method Panels does not exist on object<AccordionBlock>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
65 1
            return $this->Panels()->sort('Sort');
0 ignored issues
show
Documentation Bug introduced by
The method Panels does not exist on object<AccordionBlock>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
66 1
        }
67
        return $this->Panels();
0 ignored issues
show
Documentation Bug introduced by
The method Panels does not exist on object<AccordionBlock>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
68
    }
69
}
70
71
class AccordionBlock_Controller extends Block_Controller
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
72
{
73
    /**
74
     * @var string
75
     */
76
    private static $accordion_class = 'accordion-block';
0 ignored issues
show
Unused Code introduced by
The property $accordion_class 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...
77
78
    /**
79
     *
80
     */
81 1
    public function init()
82
    {
83
        $class = $this->AccordionClass();
84
        Requirements::javascript(THIRDPARTY_DIR . '/jquery-ui/jquery-ui.js');
85 1
        Requirements::customScript('
86
            $(function() {
87
                $( ".' . $class . '" ).accordion({
88
                    header: ".accord-header",
89
                    collapsible: true, heightStyle: "content"
90
                });
91
            });
92
        ');
93
    }
94
95
    /**
96
     * @return array
97
     */
98
    public function AccordionClass()
99
    {
100
        return Config::inst()->get('AccordionBlock_Controller', 'accordion_class');
101
    }
102
}