AccordionPanel   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 68
Duplicated Lines 0 %

Test Coverage

Coverage 53.85%

Importance

Changes 4
Bugs 0 Features 0
Metric Value
eloc 21
c 4
b 0
f 0
dl 0
loc 68
ccs 7
cts 13
cp 0.5385
rs 10
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getCMSFields() 0 14 1
A getPage() 0 11 3
1
<?php
2
3
namespace Dynamic\Elements\Accordion\Model;
4
5
use DNADesign\Elemental\Forms\TextCheckboxGroupField;
6
use Dynamic\BaseObject\Model\BaseElementObject;
7
use Dynamic\Elements\Accordion\Elements\ElementAccordion;
8
use Sheadawson\Linkable\Forms\LinkField;
9
use Sheadawson\Linkable\Models\Link;
10
use SilverStripe\Assets\Image;
11
use SilverStripe\Forms\CheckboxField;
12
use SilverStripe\Forms\FieldList;
13
use SilverStripe\Forms\TextField;
14
use SilverStripe\ORM\DataObject;
15
use SilverStripe\Security\Member;
16
use SilverStripe\Security\Permission;
17
18
/**
19
 * Class AccordionPanel
20
 * @package Dynamic\Elements\Accordion\Model
21
 *
22
 * @property int $Sort
23
 *
24
 * @property int AccordionID
25
 * @method ElementAccordion Accordion()
26
 */
27
class AccordionPanel extends BaseElementObject
28
{
29
    /**
30
     * @var array
31
     */
32
    private static $db = [
0 ignored issues
show
introduced by
The private property $db is not used, and could be removed.
Loading history...
33
        'Sort' => 'Int',
34
    ];
35
36
    /**
37
     * @var array
38
     */
39
    private static $has_one = [
0 ignored issues
show
introduced by
The private property $has_one is not used, and could be removed.
Loading history...
40
        'Accordion' => ElementAccordion::class,
41
    ];
42
43
    /**
44
     * @var array Show the panel $Title by default
45
     */
46
    private static $defaults = [
0 ignored issues
show
introduced by
The private property $defaults is not used, and could be removed.
Loading history...
47
        'ShowTitle' => true,
48
    ];
49
50
    /**
51
     * @var string
52
     */
53
    private static $default_sort = 'Sort';
0 ignored issues
show
introduced by
The private property $default_sort is not used, and could be removed.
Loading history...
54
55
    /**
56
     * @var string Database table name, default's to the fully qualified name
57
     */
58
    private static $table_name = 'AccordionPanel';
0 ignored issues
show
introduced by
The private property $table_name is not used, and could be removed.
Loading history...
59
60
    /**
61
     * @return FieldList
62
     *
63
     * @throws \Exception
64
     */
65
    public function getCMSFields()
66
    {
67 1
        $this->beforeUpdateCMSFields(function ($fields) {
68
            /** @var FieldList $fields */
69 1
            $fields->removeByName([
70 1
                'Sort',
71
                'AccordionID',
72
            ]);
73
74 1
            $fields->dataFieldByName('Image')
75 1
                ->setFolderName('Uploads/Elements/Accordions');
76 1
        });
77
78 1
        return parent::getCMSFields();
79
    }
80
81
    /**
82
     * @return null
83
     */
84
    public function getPage()
85
    {
86
        $page = null;
87
88
        if ($this->AccordionID) {
89
            if ($this->Accordion()->hasMethod('getPage')) {
90
                $page = $this->Accordion()->getPage();
91
            }
92
        }
93
94
        return $page;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $page also could return the type SilverStripe\CMS\Model\SiteTree which is incompatible with the documented return type null.
Loading history...
95
    }
96
}
97