AccordionPanel   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 129
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 7
lcom 0
cbo 5
dl 0
loc 129
ccs 30
cts 30
cp 1
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
B getCMSFields() 0 24 1
A validate() 0 10 2
A canCreate() 0 4 1
A canView() 0 4 1
A canEdit() 0 4 1
A canDelete() 0 4 1
1
<?php
2
3
class AccordionPanel extends DataObject
4
{
5
    /**
6
     * @var string
7
     */
8
    private static $singular_name = 'Accordion Panel';
9
10
    /**
11
     * @var string
12
     */
13
    private static $plural_name = 'Accordion Panels';
14
15
    /**
16
     * @var string
17
     */
18
    private static $description = 'A panel for a Accordion widget';
19
20
    /**
21
     * @var array
22
     */
23
    private static $db = array(
24
        'Title' => 'Varchar(255)',
25
        'Content' => 'HTMLText',
26
        'Sort' => 'Int',
27
    );
28
29
    /**
30
     * @var array
31
     */
32
    private static $has_one = array(
33
        'Accordion' => 'AccordionBlock',
34
        'Image' => 'Image',
35
        'BlockLink' => 'Link',
36
    );
37
38
    /**
39
     * @var string
40
     */
41
    private static $default_sort = 'Sort';
0 ignored issues
show
Unused Code introduced by
The property $default_sort 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...
42
43
    /**
44
     * @var array
45
     */
46
    private static $extensions = [
47
        'VersionedDataObject'
48
    ];
49
50
    /**
51
     * @return FieldList
52
     */
53 1
    public function getCMSFields()
54
    {
55 1
        $fields = parent::getCMSFields();
56
57 1
        $fields->removeByName(array(
58 1
            'Sort',
59 1
            'AccordionID',
60 1
        ));
61
62 1
        $fields->addFieldToTab(
63 1
            'Root.Main',
64 1
            ImageUploadField::create('Image')
65 1
                ->setFolderName('Uploads/Elements/Accordions'),
66
            'Content'
67 1
        );
68
69 1
        $fields->addFieldToTab(
70 1
            'Root.Main',
71 1
            LinkField::create('BlockLinkID', 'Link'),
72
            'Image'
73 1
        );
74
75 1
        return $fields;
76
    }
77
78
    /**
79
     * @return ValidationResult
80
     */
81 1
    public function validate()
82
    {
83 1
        $result = parent::validate();
84
85 1
        if (!$this->Title) {
0 ignored issues
show
Documentation introduced by
The property Title does not exist on object<AccordionPanel>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
86 1
            $result->error('Title is required');
87 1
        }
88
89 1
        return $result;
90
    }
91
92
    /**
93
     * @param null $member
94
     *
95
     * @return bool
96
     */
97 1
    public function canCreate($member = null)
98
    {
99 1
        return true;
100
    }
101
102
    /**
103
     * @param null $member
104
     *
105
     * @return bool
106
     */
107 1
    public function canView($member = null)
108
    {
109 1
        return true;
110
    }
111
112
    /**
113
     * @param null $member
114
     *
115
     * @return bool
116
     */
117 1
    public function canEdit($member = null)
118
    {
119 1
        return true;
120
    }
121
122
    /**
123
     * @param null $member
124
     *
125
     * @return bool
126
     */
127 1
    public function canDelete($member = null)
128
    {
129 1
        return true;
130
    }
131
}
132