Passed
Push — master ( 53e130...58b4b7 )
by Jason
02:39
created

VariationType::canEdit()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 3
c 0
b 0
f 0
nc 2
nop 2
dl 0
loc 7
rs 10
1
<?php
2
3
namespace Dynamic\Foxy\Model;
4
5
use SilverStripe\Forms\FieldList;
6
use SilverStripe\ORM\DataObject;
7
use SilverStripe\Security\Permission;
8
use SilverStripe\Security\Security;
9
10
/**
11
 * Class VariationType
12
 * @package Dynamic\Foxy\Model
13
 */
14
class VariationType extends DataObject
15
{
16
    /**
17
     * @var string
18
     */
19
    private static $table_name = 'VariationType';
0 ignored issues
show
introduced by
The private property $table_name is not used, and could be removed.
Loading history...
20
21
    /**
22
     * @var string
23
     */
24
    private static $singular_name = 'Variation Type';
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 = 'Variation Types';
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 $db = [
0 ignored issues
show
introduced by
The private property $db is not used, and could be removed.
Loading history...
35
        'Title' => 'Varchar',
36
        'SortOrder' => 'Int',
37
    ];
38
39
    /**
40
     * @var string[]
41
     */
42
    private static $has_many = [
0 ignored issues
show
introduced by
The private property $has_many is not used, and could be removed.
Loading history...
43
        'Variations' => Variation::class,
44
    ];
45
46
    /**
47
     * @var string
48
     */
49
    private static $default_sort = 'SortOrder';
0 ignored issues
show
introduced by
The private property $default_sort is not used, and could be removed.
Loading history...
50
51
    /**
52
     * @return FieldList
53
     */
54
    public function getCMSFields()
55
    {
56
        $this->beforeUpdateCMSFields(function (FieldList $fields) {
57
            $fields->removeByName([
58
                'VariationSets',
59
            ]);
60
        });
61
62
        return parent::getCMSFields();
63
    }
64
65
    /**
66
     * @param $member
67
     * @return bool|int|void
68
     */
69
    public function canCreate($member = null, $context = [])
70
    {
71
        if (!$member) {
72
            $member = Security::getCurrentUser();
73
        }
74
75
        return Permission::checkMember($member, 'MANAGE_FOXY_PRODUCTS');
76
    }
77
78
    /**
79
     * @param $member
80
     * @return bool|int|void|null
81
     */
82
    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

82
    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...
83
    {
84
        if (!$member) {
85
            $member = Security::getCurrentUser();
86
        }
87
88
        return Permission::checkMember($member, 'MANAGE_FOXY_PRODUCTS');
89
    }
90
91
    /**
92
     * @param $member
93
     * @return bool|int|void
94
     */
95
    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

95
    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...
96
    {
97
        if (!$member) {
98
            $member = Security::getCurrentUser();
99
        }
100
101
        return Permission::checkMember($member, 'MANAGE_FOXY_PRODUCTS');
102
    }
103
}
104