Passed
Push — master ( affe64...6c9189 )
by Jason
02:51
created

LocationCategory::canView()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 2
dl 0
loc 3
rs 10
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
13
/**
14
 * Class LocationCategory
15
 *
16
 * @property string $Name
17
 * @method Locations|ManyManyList LocationSet()
18
 * @method Locators|ManyManyList Locators()
19
 */
20
class LocationCategory extends DataObject
21
{
22
    /**
23
     * @var string
24
     */
25
    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...
26
27
    /**
28
     * @var string
29
     */
30
    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...
31
32
    /**
33
     * @var array
34
     */
35
    private static $db = array(
0 ignored issues
show
introduced by
The private property $db is not used, and could be removed.
Loading history...
36
        'Name' => 'Varchar(100)',
37
    );
38
39
    /**
40
     * @var array
41
     */
42
    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...
43
        'Locators' => Locator::class,
44
        'LocationSet' => Location::class,
45
    );
46
47
    /**
48
     * @var string
49
     */
50
    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...
51
52
    /**
53
     * @var string
54
     */
55
    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...
56
57
    /**
58
     * @return \SilverStripe\Forms\FieldList
59
     */
60
    public function getCMSFields()
61
    {
62
        $this->beforeUpdateCMSFields(function ($fields) {
63
            $fields->removeByName([
64
                'Locations',
65
                'LocationSet',
66
                'LinkTracking',
67
                'FileTracking',
68
            ]);
69
70
            if ($this->ID) {
71
                // Locations
72
                $config = GridFieldConfig_RelationEditor::create();
73
                $config->removeComponentsByType(GridFieldAddExistingAutocompleter::class);
74
                $config->addComponent(new GridFieldAddExistingAutocompleter());
75
                $config->removeComponentsByType(GridFieldAddNewButton::class);
76
                $locations = $this->Locations();
77
                $locationField = GridField::create('Locations', 'Locations', $locations, $config);
78
79
                $fields->addFieldsToTab('Root.Locations', array(
80
                    $locationField,
81
                ));
82
            }
83
        });
84
85
        $fields = parent::getCMSFields();
86
87
        return $fields;
88
    }
89
90
    /**
91
     * For backwards compatability
92
     * @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...
93
     */
94
    public function Locations()
95
    {
96
        return $this->LocationSet();
97
    }
98
99
    /**
100
     * @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...
101
     * @param array $context
102
     * @return bool
103
     */
104
    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

104
    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...
105
    {
106
        return true;
107
    }
108
109
    /**
110
     * @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...
111
     * @param array $context
112
     * @return bool|int
113
     */
114
    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

114
    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...
115
    {
116
        return Permission::check('Location_EDIT', 'any', $member);
117
    }
118
119
    /**
120
     * @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...
121
     * @param array $context
122
     * @return bool|int
123
     */
124
    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

124
    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...
125
    {
126
        return Permission::check('Location_DELETE', 'any', $member);
127
    }
128
129
    /**
130
     * @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...
131
     * @param array $context
132
     * @return bool|int
133
     */
134
    public function canCreate($member = null, $context = [])
135
    {
136
        return Permission::check('Location_CREATE', 'any', $member);
137
    }
138
}
139