Completed
Pull Request — master (#3)
by Jason
13:36
created

ElementSectionNavigation   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 72
Duplicated Lines 0 %

Test Coverage

Coverage 58.33%

Importance

Changes 0
Metric Value
eloc 22
dl 0
loc 72
ccs 7
cts 12
cp 0.5833
rs 10
c 0
b 0
f 0
wmc 11

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getPage() 0 12 5
A getSectionNavigation() 0 13 4
A ElementSummary() 0 3 1
A getType() 0 3 1
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 = 'sectionnav-icon';
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 1
     * @return null|\SilverStripe\ORM\DataObject
38
     * @throws \SilverStripe\ORM\ValidationException
39 1
     */
40
    public function getPage()
41
    {
42
        $area = $this->Parent();
43
44
        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 1
            }
50
        }
51
        return parent::getPage();
52
    }
53
54
    /**
55 1
     * @return bool|\SilverStripe\ORM\SS_List
56
     */
57 1
    public function getSectionNavigation()
58
    {
59
        if ($page = $this->getPage()) {
60
            if ($page->Children()->Count() > 0) {
61
                return $page->Children();
62
            } elseif ($page->Parent()) {
63 1
                return $page->Parent()->Children();
64
            } else {
65 1
                return false;
66
            }
67
        }
68
69
        return false;
70
    }
71
72
    /**
73
     * @return DBHTMLText
74
     */
75
    public function ElementSummary()
76
    {
77
        return DBField::create_field('HTMLText', '<p>Section Navigation</p>')->Summary(20);
78
    }
79
80
    /**
81
     * @return string
82
     */
83
    public function getType()
84
    {
85
        return _t(__CLASS__.'.BlockType', 'Section Navigation');
86
    }
87
}
88