Completed
Pull Request — master (#287)
by Nic
07:49
created

ShippableProduct::canDelete()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 2
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 2
1
<?php
2
3
/**
4
 * Class ShippableProduct
5
 *
6
 * @property Decimal $Weight
7
 */
8
class ShippableProduct extends FoxyStripeProduct implements PermissionProvider
9
{
10
11
    /**
12
     * @var string
13
     */
14
    private static $singular_name = 'Shippable Product';
15
    /**
16
     * @var string
17
     */
18
    private static $plural_name = 'Shippable Products';
19
    /**
20
     * @var string
21
     */
22
    private static $description = 'A physical product that is shipped to a buyer';
23
24
    /**
25
     * @var array
26
     */
27
    private static $db = [
28
        'Weight' => 'Decimal',
29
    ];
30
31
    /**
32
     * @return FieldList
33
     */
34
    public function getCMSFields()
35
    {
36
        $fields = parent::getCMSFields();
37
38
39
        return $fields;
40
    }
41
42
    /**
43
     * @return ValidationResult
44
     */
45 8
    public function validate()
46
    {
47 8
        $result = parent::validate();
48
49 8
        if ($this->Weight <= 0) {
50 1
            $result->error('This product type requires a weight greater than 0');
51 1
        }
52
53 8
        return $result;
54
    }
55
56
    /**
57
     * @param Member $member
58
     * @return boolean
59
     */
60
    public function canEdit($member = null)
61
    {
62
        return Permission::check('Product_CANCRUD');
63
    }
64
65
    /**
66
     * @param null $member
67
     * @return bool|int
68
     */
69
    public function canDelete($member = null)
70
    {
71
        return Permission::check('Product_CANCRUD');
72
    }
73
74
    /**
75
     * @param null $member
76
     * @return bool|int
77
     */
78
    public function canCreate($member = null)
79
    {
80
        return Permission::check('Product_CANCRUD');
81
    }
82
83
    /**
84
     * @param null $member
85
     * @return bool|int
86
     */
87
    public function canPublish($member = null)
0 ignored issues
show
Unused Code introduced by
The parameter $member is not used and could be removed.

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

Loading history...
88
    {
89
        return Permission::check('Product_CANCRUD');
90
    }
91
92
    /**
93
     * @return array
94
     */
95
    public function providePermissions()
96
    {
97
        return [
98
            'Product_CANCRUD' => 'Allow user to manage Products and related objects'
99
        ];
100
    }
101
102
}