ElementSectionNavigation   A
last analyzed

Complexity

Total Complexity 13

Size/Duplication

Total Lines 85
Duplicated Lines 0 %

Test Coverage

Coverage 48%

Importance

Changes 0
Metric Value
eloc 27
dl 0
loc 85
ccs 12
cts 25
cp 0.48
rs 10
c 0
b 0
f 0
wmc 13

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getPage() 0 12 5
A getSectionNavigation() 0 13 4
A getType() 0 3 1
A provideBlockSchema() 0 5 1
A getSummary() 0 6 2
1
<?php
2
3
namespace Dynamic\Elements\Section\Elements;
4
5
use DNADesign\Elemental\Models\BaseElement;
6
use DNADesign\Elemental\Models\ElementalArea;
7
use DNADesign\ElementalList\Model\ElementList;
0 ignored issues
show
Bug introduced by
The type DNADesign\ElementalList\Model\ElementList was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
8
use SilverStripe\ORM\FieldType\DBField;
9
use SilverStripe\ORM\FieldType\DBHTMLText;
10
11
/**
12
 * Class ElementSectionNavigation.
13
 */
14
class ElementSectionNavigation extends BaseElement
15
{
16
    /**
17
     * @var string
18
     */
19
    private static $icon = 'font-icon-menu';
0 ignored issues
show
introduced by
The private property $icon is not used, and could be removed.
Loading history...
20
21
    /**
22
     * @var string
23
     */
24
    private static $singular_name = 'Section Navigation Element';
0 ignored issues
show
introduced by
The private property $singular_name is not used, and could be removed.
Loading history...
25
26
    /**
27
     * @var string
28
     */
29
    private static $plural_name = 'Section Navigation Elements';
0 ignored issues
show
introduced by
The private property $plural_name is not used, and could be removed.
Loading history...
30
31
    /**
32
     * @var string
33
     */
34
    private static $table_name = 'ElementSectionNavigation';
0 ignored issues
show
introduced by
The private property $table_name is not used, and could be removed.
Loading history...
35
36
    /**
37
     * @return null|\SilverStripe\ORM\DataObject
38
     * @throws \SilverStripe\ORM\ValidationException
39
     */
40 2
    public function getPage()
41
    {
42 2
        $area = $this->Parent();
43
44 2
        if ($area instanceof ElementalArea && $area->exists()) {
45
            if ($area->getOwnerPage() instanceof ElementList && $area->getOwnerPage()->exists()) {
46
                return $area->getOwnerPage()->getPage();
47
            } else {
48
                return $area->getOwnerPage();
49
            }
50
        }
51 2
        return parent::getPage();
52
    }
53
54
    /**
55
     * @return bool|\SilverStripe\ORM\SS_List
56
     */
57 1
    public function getSectionNavigation()
58
    {
59 1
        if ($page = $this->getPage()) {
60
            if ($page->Children()->Count() > 0) {
61
                return $page->Children();
62
            } elseif ($page->Parent()) {
63
                return $page->Parent()->Children();
64
            } else {
65
                return false;
66
            }
67
        }
68
69 1
        return false;
70
    }
71
72
    /**
73
     * @return DBHTMLText
74
     */
75 1
    public function getSummary()
76
    {
77 1
        if ($this->getPage()) {
78
            return DBField::create_field('HTMLText', 'Navigation for ' . $this->getPage()->Title)->Summary(20);
79
        }
80 1
        return DBField::create_field('HTMLText', '<p>Section Navigation</p>')->Summary(20);
81
    }
82
83
    /**
84
     * @return array
85
     */
86
    protected function provideBlockSchema()
87
    {
88
        $blockSchema = parent::provideBlockSchema();
89
        $blockSchema['content'] = $this->getSummary();
90
        return $blockSchema;
91
    }
92
93
    /**
94
     * @return string
95
     */
96 1
    public function getType()
97
    {
98 1
        return _t(__CLASS__.'.BlockType', 'Section Navigation');
99
    }
100
}
101