AccordionBlock_Controller   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 3
dl 0
loc 32
ccs 0
cts 9
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A init() 0 13 1
A AccordionClass() 0 4 1
1
<?php
2
3
class AccordionBlock extends Block
4
{
5
    /**
6
     * @return string
7
     */
8 12
    public function singular_name()
9
    {
10 12
        return _t('AccordionBlock.SINGULARNAME', 'Accordion Block');
11
    }
12
13
    /**
14
     * @return string
15
     */
16 1
    public function plural_name()
17
    {
18 1
        return _t('AccordionBlock.PLURALNAME', 'Accordion Blocks');
19
    }
20
21
    /**
22
     * @var array
23
     */
24
    private static $db = array(
25
        'Content' => 'HTMLText',
26
        'SortOrder' => 'Int',
27
    );
28
29
    /**
30
     * @var array
31
     */
32
    private static $has_many = array(
33
        'Panels' => 'AccordionPanel',
34
    );
35
36
    /**
37
     * @return FieldList
38
     */
39 1
    public function getCMSFields()
40
    {
41 1
        $fields = parent::getCMSFields();
42
43 1
        $fields->removeByName(array(
44 1
            'SortOrder',
45 1
            'Panels',
46 1
        ));
47
48 1
        $config = GridFieldConfig_RecordEditor::create();
49 1
        if (class_exists('GridFieldOrderableRows')) {
50 1
            $config->addComponent(new GridFieldOrderableRows());
51 1
        }
52 1
        $config->removeComponentsByType('GridFieldAddExistingAutocompleter');
53 1
        $config->removeComponentsByType('GridFieldDeleteAction');
54 1
        $config->addComponent(new GridFieldDeleteAction(false));
55
56 1
        if ($this->ID) {
57 1
            $fields->addFieldsToTab('Root.Panels', array(
58 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...
59 1
            ));
60 1
        }
61
62 1
        return $fields;
63
    }
64
65
    /**
66
     * @return DataList
67
     */
68 1
    public function getPanelList()
69
    {
70 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...
71 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...
72
        }
73
        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...
74
    }
75
}
76
77
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...
78
{
79
    /**
80
     * @var string
81
     */
82
    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...
83
84
    /**
85
     *
86
     */
87
    public function init()
88
    {
89
        $class = $this->AccordionClass();
90
        Requirements::javascript(THIRDPARTY_DIR . '/jquery-ui/jquery-ui.js');
91
        Requirements::customScript('
92
            $(function() {
93
                $( ".' . $class . '" ).accordion({
94
                    header: ".accord-header",
95
                    collapsible: true, heightStyle: "content"
96
                });
97
            });
98
        ');
99
    }
100
101
    /**
102
     * @return array
103
     */
104
    public function AccordionClass()
105
    {
106
        return Config::inst()->get('AccordionBlock_Controller', 'accordion_class');
107
    }
108
}