ElementList::getOwnedAreaRelationName()   A
last analyzed

Complexity

Conditions 4
Paths 3

Size

Total Lines 11
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
eloc 5
c 1
b 0
f 0
nc 3
nop 0
dl 0
loc 11
rs 10
1
<?php
2
3
namespace DNADesign\ElementalList\Model;
4
5
use DNADesign\Elemental\Models\BaseElement;
6
use DNADesign\Elemental\Models\ElementalArea;
7
use DNADesign\Elemental\Extensions\ElementalAreasExtension;
8
use SilverStripe\ORM\FieldType\DBField;
9
10
class ElementList extends BaseElement
11
{
12
    private static $icon = 'font-icon-block-file-list';
0 ignored issues
show
introduced by
The private property $icon is not used, and could be removed.
Loading history...
13
14
    private static $has_one = [
0 ignored issues
show
introduced by
The private property $has_one is not used, and could be removed.
Loading history...
15
        'Elements' => ElementalArea::class
16
    ];
17
18
    private static $owns = [
0 ignored issues
show
introduced by
The private property $owns is not used, and could be removed.
Loading history...
19
        'Elements'
20
    ];
21
22
    private static $cascade_deletes = [
0 ignored issues
show
introduced by
The private property $cascade_deletes is not used, and could be removed.
Loading history...
23
        'Elements'
24
    ];
25
26
    private static $cascade_duplicates = [
0 ignored issues
show
introduced by
The private property $cascade_duplicates is not used, and could be removed.
Loading history...
27
        'Elements'
28
    ];
29
30
    private static $extensions = [
0 ignored issues
show
introduced by
The private property $extensions is not used, and could be removed.
Loading history...
31
        ElementalAreasExtension::class
32
    ];
33
34
    private static $table_name = 'ElementList';
0 ignored issues
show
introduced by
The private property $table_name is not used, and could be removed.
Loading history...
35
36
    private static $title = 'Group';
0 ignored issues
show
introduced by
The private property $title is not used, and could be removed.
Loading history...
37
38
    private static $description = 'Orderable list of elements';
0 ignored issues
show
introduced by
The private property $description is not used, and could be removed.
Loading history...
39
40
    private static $singular_name = 'list';
0 ignored issues
show
introduced by
The private property $singular_name is not used, and could be removed.
Loading history...
41
42
    private static $plural_name = 'lists';
0 ignored issues
show
introduced by
The private property $plural_name is not used, and could be removed.
Loading history...
43
44
    public function getType()
45
    {
46
        return _t(__CLASS__ . '.BlockType', 'List');
47
    }
48
49
    /**
50
     * @return DBField
51
     */
52
    public function getSummary()
53
    {
54
        $count = $this->Elements()->Elements()->Count();
0 ignored issues
show
Bug introduced by
The method Elements() does not exist on DNADesign\ElementalList\Model\ElementList. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

54
        $count = $this->/** @scrutinizer ignore-call */ Elements()->Elements()->Count();
Loading history...
55
        $suffix = $count === 1 ? 'element': 'elements';
56
57
        return 'Contains ' . $count . ' ' . $suffix;
0 ignored issues
show
Bug Best Practice introduced by
The expression return 'Contains ' . $count . ' ' . $suffix returns the type string which is incompatible with the documented return type SilverStripe\ORM\FieldType\DBField.
Loading history...
58
    }
59
60
    /**
61
     * Retrieve a elemental area relation name which this element owns
62
     *
63
     * @return string
64
     */
65
    public function getOwnedAreaRelationName()
66
    {
67
        $has_one = $this->config()->get('has_one');
68
69
        foreach ($has_one as $relationName => $relationClass) {
70
            if ($relationClass === ElementalArea::class && $relationName !== 'Parent') {
71
                return $relationName;
72
            }
73
        }
74
75
        return 'Elements';
76
    }
77
78
    public function inlineEditable()
79
    {
80
        return false;
81
    }
82
}
83