Completed
Push — master ( 92d109...8f13c5 )
by
unknown
03:44
created

OrderFeedback   A

Complexity

Total Complexity 16

Size/Duplication

Total Lines 219
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

Changes 0
Metric Value
dl 0
loc 219
rs 10
c 0
b 0
f 0
wmc 16
lcom 1
cbo 6

10 Methods

Rating   Name   Duplication   Size   Complexity  
A i18n_singular_name() 0 4 1
A i18n_plural_name() 0 4 1
A canCreate() 0 4 1
A canView() 0 15 4
A canEdit() 0 4 1
A canDelete() 0 4 1
A getCMSFields() 0 6 1
A CMSEditLink() 0 8 1
A Title() 0 4 1
A getTitle() 0 19 4
1
<?php
2
3
4
/***
5
 * Class used to describe the steps in the checkout
6
 *
7
 */
8
9
class OrderFeedback extends DataObject implements EditableEcommerceObject
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
10
{
11
    /**
12
     * standard SS variable.
13
     *
14
     * @Var Array
15
     */
16
    private static $db = array(
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
Unused Code introduced by
The property $db is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
17
        'Rating' => 'Varchar',
18
        'Note' => 'Text',
19
        'Actioned' => 'Boolean'
20
    );
21
    /**
22
     * standard SS variable.
23
     *
24
     * @Var Array
25
     */
26
    private static $has_one = array(
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
Unused Code introduced by
The property $has_one is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
27
        'Order' => 'Order'
28
    );
29
30
    /**
31
     * standard SS variable.
32
     *
33
     * @Var Array
34
     */
35
    private static $searchable_fields = array(
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
Unused Code introduced by
The property $searchable_fields is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
36
        'Rating' => 'PartialMatchFilter',
37
        'Note' => 'PartialMatchFilter',
38
        'OrderID' => array(
39
            'field' => 'NumericField',
40
            'title' => 'Order Number',
41
        )
42
    );
43
44
    /**
45
     * standard SS variable.
46
     *
47
     * @Var Array
48
     */
49
    private static $summary_fields = array(
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
Unused Code introduced by
The property $summary_fields is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
50
        'Order.Title' => 'Order',
51
        'Created' => 'When',
52
        'Rating' => 'Rating',
53
        'Note' => 'Note'
54
    );
55
56
    /**
57
     * standard SS variable.
58
     *
59
     * @Var Array
60
     */
61
    private static $casting = array(
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
Unused Code introduced by
The property $casting is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
62
        'Title' => 'Varchar'
63
    );
64
65
    /**
66
     * standard SS variable.
67
     *
68
     * @Var Array
69
     */
70
    private static $default_sorting = array(
0 ignored issues
show
Unused Code introduced by
The property $default_sorting is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
71
        'Created' => 'DESC'
72
    );
73
74
    /**
75
     * standard SS variable.
76
     *
77
     * @Var String
78
     */
79
    private static $singular_name = 'Order Feedback';
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
Unused Code introduced by
The property $singular_name is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
80
    public function i18n_singular_name()
81
    {
82
        return _t('OrderFeedback.SINGULAR_NAME', 'Order Feedback');
83
    }
84
85
    /**
86
     * standard SS variable.
87
     *
88
     * @Var String
89
     */
90
    private static $plural_name = 'Checkout Feedback Entries';
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
Unused Code introduced by
The property $plural_name is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
91
    public function i18n_plural_name()
92
    {
93
        return _t('OrderFeedback.PLURAL_NAME', 'Order Feedback Entries');
94
    }
95
96
    /**
97
     * Standard SS variable.
98
     *
99
     * @var string
100
     */
101
    private static $description = 'Customer Order Feedback';
0 ignored issues
show
Unused Code introduced by
The property $description is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
102
103
    /**
104
     * standard SS variable.
105
     *
106
     * @return bool
107
     */
108
    private static $can_create = false;
0 ignored issues
show
Unused Code introduced by
The property $can_create is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
109
110
    /**
111
     * these are only created programmatically
112
     * standard SS method.
113
     *
114
     * @param Member $member
0 ignored issues
show
Documentation introduced by
Should the type for parameter $member not be Member|null?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
115
     *
116
     * @return bool
117
     */
118
    public function canCreate($member = null)
119
    {
120
        return false;
121
    }
122
123
    /**
124
     * standard SS method.
125
     *
126
     * @param Member $member
0 ignored issues
show
Documentation introduced by
Should the type for parameter $member not be Member|null?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
127
     *
128
     * @return bool
0 ignored issues
show
Documentation introduced by
Should the return type not be boolean|string|null?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
129
     */
130
    public function canView($member = null)
131
    {
132
        if (! $member) {
133
            $member = Member::currentUser();
134
        }
135
        $extended = $this->extendedCan(__FUNCTION__, $member);
0 ignored issues
show
Documentation introduced by
$member is of type object<DataObject>|null, but the function expects a object<Member>|integer.

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...
136
        if ($extended !== null) {
137
            return $extended;
138
        }
139
        if (Permission::checkMember($member, Config::inst()->get('EcommerceRole', 'admin_permission_code'))) {
140
            return true;
141
        }
142
143
        return parent::canEdit($member);
0 ignored issues
show
Bug introduced by
It seems like $member defined by \Member::currentUser() on line 133 can also be of type object<DataObject>; however, DataObject::canEdit() does only seem to accept object<Member>|null, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
Comprehensibility Bug introduced by
It seems like you call parent on a different method (canEdit() instead of canView()). Are you sure this is correct? If so, you might want to change this to $this->canEdit().

This check looks for a call to a parent method whose name is different than the method from which it is called.

Consider the following code:

class Daddy
{
    protected function getFirstName()
    {
        return "Eidur";
    }

    protected function getSurName()
    {
        return "Gudjohnsen";
    }
}

class Son
{
    public function getFirstName()
    {
        return parent::getSurname();
    }
}

The getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
144
    }
145
146
    /**
147
     * standard SS method.
148
     *
149
     * @param Member $member
0 ignored issues
show
Documentation introduced by
Should the type for parameter $member not be Member|null?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
150
     *
151
     * @return bool
152
     */
153
    public function canEdit($member = null)
154
    {
155
        return false;
156
    }
157
158
    /**
159
     * standard SS method.
160
     *
161
     * @param Member $member
0 ignored issues
show
Documentation introduced by
Should the type for parameter $member not be Member|null?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
162
     *
163
     * @return bool
164
     */
165
    public function canDelete($member = null)
166
    {
167
        return false;
168
    }
169
170
    /**
171
     * standard SS method.
172
     *
173
     * @return FieldList
174
     */
175
    public function getCMSFields()
176
    {
177
        $fields = parent::getCMSFields();
178
179
        return $fields;
180
    }
181
182
    /**
183
     * link to edit the record.
184
     *
185
     * @param string | Null $action - e.g. edit
186
     *
187
     * @return string
188
     */
189
    public function CMSEditLink($action = null)
190
    {
191
        return Controller::join_links(
192
            Director::baseURL(),
193
            '/sales-advanced/shop/'.$this->ClassName.'/EditForm/field/'.$this->ClassName.'/item/'.$this->ID.'/',
194
            $action
195
        );
196
    }
197
198
    /**
199
     * casted variable.
200
     *
201
     * @return string
202
     */
203
    public function Title()
204
    {
205
        return $this->getTitle();
206
    }
207
    public function getTitle()
208
    {
209
        $string = '';
210
        $array = array(
211
            'Created',
212
            'OrderID',
213
            'Rating',
214
            'Note'
215
        );
216
        foreach($array as $field) {
217
            if($this->$field) {
218
                if($string) {
219
                    $string .= ' - ';
220
                }
221
                $string .= $this->$field;
222
            }
223
        }
224
        return $string;
225
    }
226
227
}
228