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

AccordionBlock::canView()   B

Complexity

Conditions 5
Paths 4

Size

Total Lines 14
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 15.5468

Importance

Changes 0
Metric Value
dl 0
loc 14
ccs 2
cts 8
cp 0.25
rs 8.8571
c 0
b 0
f 0
cc 5
eloc 7
nc 4
nop 1
crap 15.5468
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
}