Passed
Pull Request — master (#6)
by Jason
03:27 queued 01:47
created

CartReservation::getCMSFields()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 3
c 1
b 0
f 0
dl 0
loc 6
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Dynamic\Foxy\Inventory\Model;
4
5
use SilverStripe\CMS\Model\SiteTree;
6
use SilverStripe\Forms\FieldList;
7
use SilverStripe\Forms\ReadonlyField;
8
use SilverStripe\ORM\DataObject;
9
use SilverStripe\Security\Permission;
10
11
class CartReservation extends DataObject
12
{
13
    /**
14
     * @var string
15
     */
16
    private static $singular_name = 'Cart Reservation';
0 ignored issues
show
introduced by
The private property $singular_name is not used, and could be removed.
Loading history...
17
18
    /**
19
     * @var string
20
     */
21
    private static $plural_name = 'Cart Reservations';
0 ignored issues
show
introduced by
The private property $plural_name is not used, and could be removed.
Loading history...
22
23
    /**
24
     * @var string
25
     */
26
    private static $table_name = 'FoxyCartReservation';
0 ignored issues
show
introduced by
The private property $table_name is not used, and could be removed.
Loading history...
27
28
    /**
29
     * @var array
30
     */
31
    private static $db = [
0 ignored issues
show
introduced by
The private property $db is not used, and could be removed.
Loading history...
32
        'ReservationCode' => 'Varchar(255)',
33
        'CartProductID' => 'Int',
34
        'Code' => 'Varchar(255)',
35
        'Expires' => 'DBDatetime',
36
    ];
37
38
    /**
39
     * @var array
40
     */
41
    private static $has_one = [
0 ignored issues
show
introduced by
The private property $has_one is not used, and could be removed.
Loading history...
42
        'Product' => SiteTree::class,
43
    ];
44
45
    /**
46
     * @var array
47
     */
48
    private static $indexes = [
0 ignored issues
show
introduced by
The private property $indexes is not used, and could be removed.
Loading history...
49
        'foxy-reservation-code' => [
50
            'type' => 'unique',
51
            'columns' => ['ReservationCode'],
52
        ],
53
    ];
54
55
    /**
56
     * @var array
57
     */
58
    private static $summary_fields = [
0 ignored issues
show
introduced by
The private property $summary_fields is not used, and could be removed.
Loading history...
59
        'ReservationCode' => 'Reservation',
60
        'Expires.Nice' => 'Expires',
61
    ];
62
63
    /**
64
     * @return FieldList
65
     */
66
    public function getCMSFields()
67
    {
68
        $this->beforeUpdateCMSFields(function (FieldList $fields) {
69
            $fields->addFieldToTab('Root.Main', ReadonlyField::create('ReservationCode')->setTitle('Reservation Code'));
70
        });
71
        return parent::getCMSFields();
72
    }
73
74
    /**
75
     *
76
     */
77
    public function onBeforeWrite()
78
    {
79
        parent::onBeforeWrite();
80
        if (!$this->ProductID) {
81
            if ($product = SiteTree::get()->filter('Code', $this->Code)->first()) {
0 ignored issues
show
Bug Best Practice introduced by
The property Code does not exist on Dynamic\Foxy\Inventory\Model\CartReservation. Since you implemented __get, consider adding a @property annotation.
Loading history...
82
                $this->ProductID = $product->ID;
0 ignored issues
show
Bug Best Practice introduced by
The property ProductID does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
83
            }
84
        }
85
    }
86
87
    /**
88
     * @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...
89
     * @param array $context
90
     * @return bool
91
     */
92
    public function canCreate($member = null, $context = [])
93
    {
94
        return false;
95
    }
96
97
    /**
98
     * @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...
99
     * @return bool
100
     */
101
    public function canEdit($member = null)
102
    {
103
        return false;
104
    }
105
106
    /**
107
     * @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...
108
     * @return bool|int
109
     */
110
    public function canDelete($member = null)
111
    {
112
        return Permission::check('ADMIN', 'any', \Security::getCurrentUser());
0 ignored issues
show
Bug introduced by
The method getCurrentUser() does not exist on Security. ( Ignorable by Annotation )

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

112
        return Permission::check('ADMIN', 'any', \Security::/** @scrutinizer ignore-call */ getCurrentUser());

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
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
     * @return bool
118
     */
119
    public function canView($member = null)
120
    {
121
        return true;
122
    }
123
}
124