Completed
Push — master ( 6214aa...daa834 )
by Jason
08:16
created

AccordionBlock   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 6
dl 0
loc 56
ccs 19
cts 19
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B getCMSFields() 0 25 3
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
    public function getCMSFields()
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
}