Completed
Pull Request — master (#1)
by Nic
09:01
created

ProductWishList::getFrontEndActions()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 16
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
loc 16
ccs 11
cts 11
cp 1
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 9
nc 4
nop 1
crap 3
1
<?php
2
3
/**
4
 * Class ProductWishList
5
 *
6
 * @property string $Title
7
 * @property bool $Private
8
 * @property int $MemberID
9
 * @method Member $Member
10
 */
11
class ProductWishList extends DataObject implements PermissionProvider, Dynamic\ViewableDataObject\VDOInterfaces\ViewableDataObjectInterface
12
{
13
14
    /**
15
     * @var array
16
     */
17
    private static $db = [
18
        'Title' => 'Varchar(100)',
19
        'Private' => 'Boolean',
20
    ];
21
22
    /**
23
     * @var array
24
     */
25
    private static $has_one = [
26
        'Member' => 'Member',
27
    ];
28
29
    /**
30
     * @param null $params
31
     *
32
     * @return FieldList
33
     */
34 2
    public function getFrontEndFields($params = null)
35
    {
36 2
        $fields = parent::getFrontEndFields($params);
37
38 2
        $fields->removeByName('MemberID');
39
40 2
        return $fields;
41
    }
42
43
    /**
44
     * @param bool $showCancel
45
     *
46
     * @return FieldList
47
     */
48 2
    public function getFrontEndActions($showCancel = false)
49
    {
50 2
        $processTitle = ($this->getIsEditing()) ? "Update {$this->i18n_singular_name()}" : "Create {$this->i18n_singular_name()}";
51 2
        $actions = FieldList::create(
52 2
            FormAction::create('doProcessWishList')
53 2
                      ->setTitle($processTitle)
54 2
        );
55
56 2
        if ($showCancel === true) {
57 1
            $actions->insertBefore('action_doProcessWishList', CancelFormAction::create('Cancel'));
58 1
        }
59
60 2
        $this->extend('updateFrontEndActions', $actions);
61
62 2
        return $actions;
63
    }
64
65
    /**
66
     * @return RequiredFields
67
     */
68 2
    public function getFrontEndRequiredFields()
69
    {
70 2
        $fields = RequiredFields::create([
71 2
            'Title',
72 2
        ]);
73
74 2
        $this->extend('updateFrontEndRequiredFields', $fields);
75
76 2
        return $fields;
77
    }
78
79
    /**
80
     * @return bool
81
     */
82 2
    public function getIsEditing()
83
    {
84 2
        $params = Controller::curr()->getRequest()->latestParams();
85
86 2
        return isset($params['Action']) && $params['Action'] == 'update' && isset($params['ID']) && $params['ID'] > 0;
87
    }
88
89
    /**
90
     * set ParentPage for ViewableDataobject
91
     *
92
     * @return string
93
     */
94
    public function getParentPage()
95
    {
96
        return ProductWishListPage::get()->first();
97
    }
98
99
    /**
100
     * @return String|bool
101
     */
102 1
    public function getUpdateLink()
103
    {
104 1
        return ($this->ID > 0) ? Controller::join_links('update', $this->ID) : false;
105
    }
106
107
    /**
108
     * set ViewAction for ViewableDataobject
109
     *
110
     * @return string
111
     */
112 1
    public function getViewAction()
113
    {
114 1
        return 'view';
115
    }
116
117
    /**
118
     * @return array
119
     */
120 1
    public function providePermissions()
121
    {
122
        return array(
123 1
            'WishList_EDIT' => 'Edit a Wish List',
124 1
            'WishList_DELETE' => 'Delete a Wish List',
125 1
            'WishList_CREATE' => 'Create a Wish List',
126 1
            'WishList_VIEW' => 'View a Wish List',
127 1
        );
128
    }
129
130
    /**
131
     * @param Member|null $member
132
     *
133
     * @return bool|int
134
     */
135 1
    public function canEdit($member = null)
136
    {
137 1
        return Permission::check('WishList_EDIT', 'any', $member);
138
    }
139
140
    /**
141
     * @param Member|null $member
142
     *
143
     * @return bool|int
144
     */
145 1
    public function canDelete($member = null)
146
    {
147 1
        return Permission::check('WishList_DELETE', 'any', $member);
148
    }
149
150
    /**
151
     * @param Member|null $member
152
     *
153
     * @return bool|int
154
     */
155 1
    public function canCreate($member = null)
156
    {
157 1
        return Permission::check('WishList_CREATE', 'any', $member);
158
    }
159
160
    /**
161
     * @param Member|null $member
162
     *
163
     * @return bool
164
     */
165 1
    public function canView($member = null)
166
    {
167 1
        $member = ($member === null) ? Member::currentUser() : $member;
168
169 1
        return (!$this->Private) || ((Permission::check('WishList_VIEW', 'any', $member) && $member->ID == $this->MemberID) || Permission::check('ADMIN'));
0 ignored issues
show
Documentation introduced by
$member is of type object<DataObject>, but the function expects a integer|object<Member>|null.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
170
    }
171
172
}