Completed
Push — master ( 98ffbc...f44bfd )
by Jason
05:56
created

PageSectionObject   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 141
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 0%

Importance

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

6 Methods

Rating   Name   Duplication   Size   Complexity  
B getCMSFields() 0 25 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
/**
4
 * Class PageSectionObject
5
 *
6
 * @property string $Name
7
 * @property string $Title
8
 * @property HTMLText $Content
9
 * @property int $SortOrder
10
 * @property int $ImageID
11
 * @property int $PageSectionBlockID
12
 */
13
class PageSectionObject extends DataObject
14
{
15
    /**
16
     * @return string
17
     */
18
    private static $singular_name = 'Page Section';
19
20
    /**
21
     * @return string
22
     */
23
    private static $plural_name = 'Page Sections';
24
25
    /**
26
     * @var array
27
     */
28
    private static $db = array(
29
        'Name' => 'Varchar(255)',
30
        'Title' => 'Varchar(255)',
31
        'Content' => 'HTMLText',
32
        'SortOrder' => 'Int',
33
    );
34
35
    /**
36
     * @var array
37
     */
38
    private static $has_one = array(
39
        'Image' => 'Image',
40
        'PageSectionBlock' => 'PageSectionBlock',
41
        'Link' => 'Link',
42
    );
43
44
    /**
45
     * @var string
46
     */
47
    private static $default_sort = 'Name ASC';
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...
48
49
    /**
50
     * @var array
51
     */
52
    private static $summary_fields = array(
53
        'Image.CMSThumbnail' => 'Image',
54
        'Name' => 'Name',
55
        'Title' => 'Title',
56
    );
57
58
    /**
59
     * @var array
60
     */
61
    private static $searchable_fields = array(
62
        'Name' => 'Name',
63
        'Title' => 'Title',
64
    );
65
66
    /**
67
     * @return FieldList
68
     */
69
    public function getCMSFields()
70
    {
71
        $this->beforeUpdateCMSFields(function ($fields) {
72
            $fields->addFieldToTab(
73
                'Root.Main',
74
                LinkField::create('LinkID', 'Link'),
75
                'Content'
76
            );
77
        });
78
79
        $fields = parent::getCMSFields();
80
81
        $fields->removeByName(array(
82
            'PageSectionBlockID',
83
            'SortOrder',
84
        ));
85
86
        $fields->dataFieldByName('Name')->setDescription('For internal reference only');
87
88
        $image = $fields->dataFieldByName('Image');
89
        $image->setFolderName('Uploads/PageSections');
90
        $fields->insertBefore($image, 'Content');
0 ignored issues
show
Documentation introduced by
'Content' is of type string, but the function expects a object<FormField>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
91
92
        return $fields;
93
    }
94
95
    /**
96
     * @return ValidationResult
97
     */
98
    public function validate()
99
    {
100
        $result = parent::validate();
101
102
        if (!$this->Name) {
103
            $result->error('Name is requied before you can save');
104
        }
105
106
        return $result;
107
    }
108
109
    /**
110
     * Set permissions, allow all users to access by default.
111
     * Override in descendant classes, or use PermissionProvider.
112
     */
113
114
    /**
115
     * @param null $member
116
     *
117
     * @return bool
118
     */
119
    public function canCreate($member = null)
120
    {
121
        return true;
122
    }
123
124
    /**
125
     * @param null $member
126
     *
127
     * @return bool
128
     */
129
    public function canView($member = null)
130
    {
131
        return true;
132
    }
133
134
    /**
135
     * @param null $member
136
     *
137
     * @return bool
138
     */
139
    public function canEdit($member = null)
140
    {
141
        return true;
142
    }
143
144
    /**
145
     * @param null $member
146
     *
147
     * @return bool
148
     */
149
    public function canDelete($member = null)
150
    {
151
        return true;
152
    }
153
}