Completed
Push — master ( 3b65eb...dc665d )
by Nicolaas
11:00 queued 02:51
created

code/model/process/OrderFeedback.php (3 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

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
10
{
11
    /**
12
     * standard SS variable.
13
     *
14
     * @Var Array
15
     */
16
    private static $db = array(
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(
27
        'Order' => 'Order'
28
    );
29
30
    /**
31
     * standard SS variable.
32
     *
33
     * @Var Array
34
     */
35
    private static $searchable_fields = array(
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(
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(
62
        'Title' => 'Varchar'
63
    );
64
65
    /**
66
     * standard SS variable.
67
     *
68
     * @Var Array
69
     */
70
    private static $default_sorting = array(
71
        'Created' => 'DESC'
72
    );
73
74
    /**
75
     * standard SS variable.
76
     *
77
     * @Var String
78
     */
79
    private static $singular_name = 'Order Feedback';
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';
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';
102
103
    /**
104
     * standard SS variable.
105
     *
106
     * @return bool
107
     */
108
    private static $can_create = false;
109
110
    /**
111
     * these are only created programmatically
112
     * standard SS method.
113
     *
114
     * @param Member $member
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
127
     *
128
     * @return bool
129
     */
130
    public function canView($member = null)
131
    {
132
        if (! $member) {
133
            $member = Member::currentUser();
134
        }
135
        $extended = $this->extendedCan(__FUNCTION__, $member);
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
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
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
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 CMSEditLinkAPI::find_edit_link_for_object($this, $action);
192
    }
193
194
    /**
195
     * casted variable.
196
     *
197
     * @return string
198
     */
199
    public function Title()
200
    {
201
        return $this->getTitle();
202
    }
203
    public function getTitle()
204
    {
205
        $string = $this->Created;
206
        if($this->Order()) {
207
            $string .= ' ('.$this->Order()->getTitle().')';
208
        }
209
        $string .= ' - '.$this->Rating;
210
        if($this->Note) {
211
            $string .= ' / '.$this->Note;
0 ignored issues
show
The property Note does not exist on object<OrderFeedback>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
212
        }
213
        return $string;
214
    }
215
216
}
217