Completed
Pull Request — master (#2)
by
unknown
01:51
created

ElementList   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Importance

Changes 2
Bugs 1 Features 0
Metric Value
c 2
b 1
f 0
dl 0
loc 41
rs 10
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getType() 0 3 1
A getSummary() 0 7 3
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
9
use SilverStripe\Core\Config\Config;
10
use SilverStripe\ORM\ArrayList;
11
use SilverStripe\ORM\FieldType\DBField;
12
13
class ElementList extends BaseElement
14
{
15
    private static $icon = 'dnadesign/silverstripe-elemental-list:images/list.svg';
0 ignored issues
show
Unused Code introduced by
The property $icon 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...
16
17
    private static $has_one = [
0 ignored issues
show
Unused Code introduced by
The property $has_one 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...
18
        'Elements' => ElementalArea::class
19
    ];
20
21
    private static $owns = [
0 ignored issues
show
Unused Code introduced by
The property $owns 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...
22
        'Elements'
23
    ];
24
25
    private static $cascade_deletes = [
0 ignored issues
show
Unused Code introduced by
The property $cascade_deletes 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...
26
        'Elements'
27
    ];
28
29
    private static $extensions = [
0 ignored issues
show
Unused Code introduced by
The property $extensions 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...
30
        ElementalAreasExtension::class
31
    ];
32
33
    private static $table_name = 'ElementList';
0 ignored issues
show
Unused Code introduced by
The property $table_name 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...
34
35
    private static $title = 'Group';
0 ignored issues
show
Unused Code introduced by
The property $title 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...
36
37
    private static $description = 'Orderable list of elements';
0 ignored issues
show
Unused Code introduced by
The property $description 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...
38
39
    public function getType()
40
    {
41
        return _t(__CLASS__ . '.BlockType', 'List');
42
    }
43
44
    /**
45
     * @return DBField
46
     */
47
    public function getSummary()
48
    {
49
        $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

49
        $count = $this->/** @scrutinizer ignore-call */ Elements()->Elements()->Count();
Loading history...
50
        $suffix = $count === 1 ? 'element': 'elements';
51
        $summary = $this->ListDescription ? DBField::create_field('HTMLText', $this->ListDescription)->Summary(10) . '<br />': '';
0 ignored issues
show
Bug Best Practice introduced by
The property ListDescription does not exist on DNADesign\ElementalList\Model\ElementList. Since you implemented __get, consider adding a @property annotation.
Loading history...
52
53
        return DBField::create_field('HTMLText', $summary . ' <span class="el-meta">Contains ' . $count . ' ' . $suffix . '</span>');
54
    }
55
}
56