Passed
Push — enhancement/more-config-option... ( e4871a...997483 )
by Matthew
03:47 queued 42s
created

LocationCategory::getCMSFields()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 33
Code Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 0 Features 1
Metric Value
cc 2
eloc 20
c 3
b 0
f 1
nc 1
nop 0
dl 0
loc 33
rs 9.6
1
<?php
2
3
namespace Dynamic\Locator;
4
5
use SilverStripe\Forms\GridField\GridField;
6
use SilverStripe\Forms\GridField\GridFieldAddExistingAutocompleter;
7
use SilverStripe\Forms\GridField\GridFieldAddNewButton;
8
use SilverStripe\Forms\GridField\GridFieldConfig_RelationEditor;
9
use SilverStripe\ORM\DataObject;
10
use SilverStripe\ORM\ManyManyList;
11
use SilverStripe\Security\Permission;
12
use Symbiote\GridFieldExtensions\GridFieldAddExistingSearchButton;
13
14
/**
15
 * Class LocationCategory
16
 *
17
 * @property string $Name
18
 * @method Locations|ManyManyList LocationSet()
19
 * @method Locators|ManyManyList Locators()
20
 */
21
class LocationCategory extends DataObject
22
{
23
    /**
24
     * @var string
25
     */
26
    private static $singular_name = 'Category';
0 ignored issues
show
introduced by
The private property $singular_name is not used, and could be removed.
Loading history...
27
28
    /**
29
     * @var string
30
     */
31
    private static $plural_name = 'Categories';
0 ignored issues
show
introduced by
The private property $plural_name is not used, and could be removed.
Loading history...
32
33
    /**
34
     * @var array
35
     */
36
    private static $db = array(
0 ignored issues
show
introduced by
The private property $db is not used, and could be removed.
Loading history...
37
        'Name' => 'Varchar(100)',
38
    );
39
40
    /**
41
     * @var array
42
     */
43
    private static $belongs_many_many = array(
0 ignored issues
show
introduced by
The private property $belongs_many_many is not used, and could be removed.
Loading history...
44
        'Locators' => Locator::class,
45
        'LocationSet' => Location::class,
46
    );
47
48
    /**
49
     * @var string
50
     */
51
    private static $table_name = 'LocationCategory';
0 ignored issues
show
introduced by
The private property $table_name is not used, and could be removed.
Loading history...
52
53
    /**
54
     * @var string
55
     */
56
    private static $default_sort = 'Name';
0 ignored issues
show
introduced by
The private property $default_sort is not used, and could be removed.
Loading history...
57
58
    /**
59
     * @return \SilverStripe\Forms\FieldList
60
     */
61
    public function getCMSFields()
62
    {
63
        $this->beforeUpdateCMSFields(function ($fields) {
64
            $fields->removeByName([
65
                'Locations',
66
                'LocationSet',
67
                'Locators',
68
                'LinkTracking',
69
                'FileTracking',
70
            ]);
71
72
            if ($this->ID) {
73
                // Locations
74
                $config = GridFieldConfig_RelationEditor::create();
75
                $config->removeComponentsByType([
76
                    GridFieldAddExistingAutocompleter::class,
77
                    GridFieldAddNewButton::class
78
                ])
79
                    ->addComponents([
80
                        new GridFieldAddExistingSearchButton(),
81
                    ]);
82
                $locations = $this->Locations();
83
                $locationField = GridField::create('Locations', 'Locations', $locations, $config);
84
85
                $fields->addFieldsToTab('Root.Main', array(
86
                    $locationField,
87
                ));
88
            }
89
        });
90
91
        $fields = parent::getCMSFields();
92
93
        return $fields;
94
    }
95
96
    /**
97
     * For backwards compatability
98
     * @return Locations|ManyManyList
0 ignored issues
show
Bug introduced by
The type Dynamic\Locator\Locations 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...
99
     */
100
    public function Locations()
101
    {
102
        return $this->LocationSet();
103
    }
104
105
    /**
106
     * @param null $member
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $member is correct as it would always require null to be passed?
Loading history...
107
     * @param array $context
108
     * @return bool
109
     */
110
    public function canView($member = null, $context = [])
0 ignored issues
show
Unused Code introduced by
The parameter $context is not used and could be removed. ( Ignorable by Annotation )

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

110
    public function canView($member = null, /** @scrutinizer ignore-unused */ $context = [])

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
111
    {
112
        return true;
113
    }
114
115
    /**
116
     * @param null $member
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $member is correct as it would always require null to be passed?
Loading history...
117
     * @param array $context
118
     * @return bool|int
119
     */
120
    public function canEdit($member = null, $context = [])
0 ignored issues
show
Unused Code introduced by
The parameter $context is not used and could be removed. ( Ignorable by Annotation )

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

120
    public function canEdit($member = null, /** @scrutinizer ignore-unused */ $context = [])

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
121
    {
122
        return Permission::check('Location_EDIT', 'any', $member);
123
    }
124
125
    /**
126
     * @param null $member
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $member is correct as it would always require null to be passed?
Loading history...
127
     * @param array $context
128
     * @return bool|int
129
     */
130
    public function canDelete($member = null, $context = [])
0 ignored issues
show
Unused Code introduced by
The parameter $context is not used and could be removed. ( Ignorable by Annotation )

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

130
    public function canDelete($member = null, /** @scrutinizer ignore-unused */ $context = [])

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
131
    {
132
        return Permission::check('Location_DELETE', 'any', $member);
133
    }
134
135
    /**
136
     * @param null $member
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $member is correct as it would always require null to be passed?
Loading history...
137
     * @param array $context
138
     * @return bool|int
139
     */
140
    public function canCreate($member = null, $context = [])
141
    {
142
        return Permission::check('Location_CREATE', 'any', $member);
143
    }
144
}
145