Completed
Pull Request — master (#62)
by Jason
12:32
created

AccordionPanel::getCMSFields()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 24
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 16
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 24
ccs 16
cts 16
cp 1
rs 8.9713
c 0
b 0
f 0
cc 1
eloc 15
nc 1
nop 0
crap 1
1
<?php
2
3
namespace Dynamic\DynamicBlocks\Model;
4
5
use Dynamic\DynamicBlocks\Block\AccordionBlock;
6
use SilverStripe\AssetAdmin\Forms\UploadField;
7
use SilverStripe\Assets\Image;
8
use SilverStripe\ORM\DataObject;
9
10
class AccordionPanel extends DataObject
11
{
12
    /**
13
     * @var string
14
     */
15
    private static $singular_name = 'Accordion Panel';
16
17
    /**
18
     * @var string
19
     */
20
    private static $plural_name = 'Accordion Panels';
21
22
    /**
23
     * @var string
24
     */
25
    private static $description = 'A panel for a Accordion widget';
26
27
    /**
28
     * @var array
29
     */
30
    private static $db = array(
31
        'Title' => 'Varchar(255)',
32
        'Content' => 'HTMLText',
33
        'Sort' => 'Int',
34
    );
35
36
    /**
37
     * @var array
38
     */
39
    private static $has_one = array(
40
        'Accordion' => AccordionBlock::class,
41
        'Image' => Image::class,
42
        //'BlockLink' => 'Link', // todo readd once Linkable is SS4 compatible
0 ignored issues
show
Unused Code Comprehensibility introduced by
58% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
43
    );
44
45
    /**
46
     * @var string
47
     */
48
    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...
49
50
    /**
51
     * @return \SilverStripe\Forms\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
            UploadField::create('Image')
65 1
            //    ->setFolderName('Uploads/Elements/Accordions')
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
66
            ,
67 1
            'Content'
68
        );
69 1
70 1
        /* // todo readd once Linkable is SS4 compatible
0 ignored issues
show
Unused Code Comprehensibility introduced by
60% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
71 1
        $fields->addFieldToTab(
72
            'Root.Main',
73 1
            LinkField::create('BlockLinkID', 'Link'),
74
            'Image'
75 1
        );
76
        */
77
78
        return $fields;
79
    }
80
81 1
    /**
82
     * @return \SilverStripe\ORM\ValidationResult
83 1
     */
84
    public function validate()
85 1
    {
86 1
        $result = parent::validate();
87 1
88
        if (!$this->Title) {
0 ignored issues
show
Documentation introduced by
The property Title does not exist on object<Dynamic\DynamicBl...s\Model\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...
89 1
            $result->addError('Title is required');
90
        }
91
92
        return $result;
93
    }
94
95
    /**
96
     * @param null $member
97 1
     * @param array $context
98
     * @return bool
99 1
     */
100
    public function canCreate($member = null, $context = [])
101
    {
102
        return true;
103
    }
104
105
    /**
106
     * @param null $member
107 1
     * @param array $context
108
     * @return bool
109 1
     */
110
    public function canView($member = null, $context = [])
0 ignored issues
show
Unused Code introduced by
The parameter $context is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
111
    {
112
        return true;
113
    }
114
115
    /**
116
     * @param null $member
117 1
     * @param array $context
118
     * @return bool
119 1
     */
120
    public function canEdit($member = null, $context = [])
0 ignored issues
show
Unused Code introduced by
The parameter $context is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
121
    {
122
        return true;
123
    }
124
125
    /**
126
     * @param null $member
127 1
     * @param array $context
128
     * @return bool
129 1
     */
130
    public function canDelete($member = null, $context = [])
0 ignored issues
show
Unused Code introduced by
The parameter $context is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
131
    {
132 1
        return true;
133
    }
134
}
135