Completed
Pull Request — master (#62)
by Jason
15:39
created

AccordionPanel::getCMSFields()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 27
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 16
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 27
ccs 16
cts 16
cp 1
rs 8.8571
c 0
b 0
f 0
cc 1
eloc 10
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\ORM\DataObject;
8
9
class AccordionPanel extends DataObject
10
{
11
    /**
12
     * @var string
13
     */
14
    private static $singular_name = 'Accordion Panel';
15
16
    /**
17
     * @var string
18
     */
19
    private static $plural_name = 'Accordion Panels';
20
21
    /**
22
     * @var string
23
     */
24
    private static $description = 'A panel for a Accordion widget';
25
26
    /**
27
     * @var array
28
     */
29
    private static $db = array(
30
        'Title' => 'Varchar(255)',
31
        'Content' => 'HTMLText',
32
        'Sort' => 'Int',
33
    );
34
35
    /**
36
     * @var array
37
     */
38
    private static $has_one = array(
39
        'Accordion' => AccordionBlock::class,
40
        'Image' => Image::class,
41
        //'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...
42
    );
43
44
    /**
45
     * @var string
46
     */
47
    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...
48
49
    /**
50
     * @return \SilverStripe\Forms\FieldList
51
     */
52
    public function getCMSFields()
53 1
    {
54
        $fields = parent::getCMSFields();
55 1
56
        $fields->removeByName(array(
57 1
            'Sort',
58 1
            'AccordionID',
59 1
        ));
60 1
61
        $fields->addFieldToTab(
62 1
            'Root.Main',
63 1
            UploadField::create('Image')
64 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...
65 1
            ,
66
            'Content'
67 1
        );
68
69 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...
70 1
        $fields->addFieldToTab(
71 1
            'Root.Main',
72
            LinkField::create('BlockLinkID', 'Link'),
73 1
            'Image'
74
        );
75 1
        */
76
77
        return $fields;
78
    }
79
80
    /**
81 1
     * @return \SilverStripe\ORM\ValidationResult
82
     */
83 1
    public function validate()
84
    {
85 1
        $result = parent::validate();
86 1
87 1
        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...
88
            $result->error('Title is required');
0 ignored issues
show
Bug introduced by
The method error() does not seem to exist on object<SilverStripe\ORM\ValidationResult>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
89 1
        }
90
91
        return $result;
92
    }
93
94
    /**
95
     * @param null $member
96
     * @param array $context
97 1
     * @return bool
98
     */
99 1
    public function canCreate($member = null, $context = [])
100
    {
101
        return true;
102
    }
103
104
    /**
105
     * @param null $member
106
     * @param array $context
107 1
     * @return bool
108
     */
109 1
    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...
110
    {
111
        return true;
112
    }
113
114
    /**
115
     * @param null $member
116
     * @param array $context
117 1
     * @return bool
118
     */
119 1
    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...
120
    {
121
        return true;
122
    }
123
124
    /**
125
     * @param null $member
126
     * @param array $context
127 1
     * @return bool
128
     */
129 1
    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...
130
    {
131
        return true;
132 1
    }
133
}
134