Passed
Push — master ( c6afeb...a80cbd )
by Nic
02:33
created

Order::parseOrderDetails()   B

Complexity

Conditions 8
Paths 15

Size

Total Lines 53
Code Lines 29

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 8
eloc 29
nc 15
nop 0
dl 0
loc 53
rs 8.2114
c 0
b 0
f 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
namespace Dynamic\Foxy\Orders\Model;
4
5
use Dynamic\Foxy\Extension\Purchasable;
6
use Dynamic\Foxy\Orders\Foxy\Transaction;
0 ignored issues
show
Bug introduced by
The type Dynamic\Foxy\Orders\Foxy\Transaction was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
7
use SilverStripe\CMS\Model\SiteTree;
8
use SilverStripe\Forms\DateField;
9
use SilverStripe\ORM\DataObject;
10
use SilverStripe\ORM\FieldType\DBHTMLVarchar;
11
use SilverStripe\ORM\HasManyList;
12
use SilverStripe\ORM\ValidationException;
13
use SilverStripe\Security\Member;
14
use SilverStripe\Security\Permission;
15
use SilverStripe\Security\PermissionProvider;
16
17
/**
18
 * Class Order
19
 * @package Dynamic\Foxy\Model
20
 *
21
 * @property \SilverStripe\ORM\FieldType\DBInt StoreID
22
 * @property \SilverStripe\ORM\FieldType\DBInt OrderID
23
 * @property \SilverStripe\ORM\FieldType\DBVarchar Email
24
 * @property \SilverStripe\ORM\FieldType\DBDatetime TransactionDate
25
 * @property \SilverStripe\ORM\FieldType\DBCurrency ProductTotal
26
 * @property \SilverStripe\ORM\FieldType\DBCurrency TaxTotal
27
 * @property \SilverStripe\ORM\FieldType\DBCurrency ShippingTotal
28
 * @property \SilverStripe\ORM\FieldType\DBCurrency OrderTotal
29
 * @property \SilverStripe\ORM\FieldType\DBVarchar ReceiptURL
30
 * @property \SilverStripe\ORM\FieldType\DBVarchar OrderStatus
31
 * @property \SilverStripe\ORM\FieldType\DBText Response
32
 *
33
 * @property int MemberID
34
 * @method Member Member
35
 *
36
 * @method HasManyList Details
37
 */
38
class Order extends DataObject implements PermissionProvider
39
{
40
    /**
41
     * @var array
42
     */
43
    private static $db = [
0 ignored issues
show
introduced by
The private property $db is not used, and could be removed.
Loading history...
44
        'StoreID' => 'Int',
45
        'OrderID' => 'Int',
46
        'Email' => 'Varchar(255)',
47
        'TransactionDate' => 'DBDatetime',
48
        'ProductTotal' => 'Currency',
49
        'TaxTotal' => 'Currency',
50
        'ShippingTotal' => 'Currency',
51
        'OrderTotal' => 'Currency',
52
        'ReceiptURL' => 'Varchar(255)',
53
        'OrderStatus' => 'Varchar(255)',
54
        'Response' => 'Text',
55
        'CustomerID' => 'Int',
56
    ];
57
58
    /**
59
     * @var array
60
     */
61
    private static $has_one = [
0 ignored issues
show
introduced by
The private property $has_one is not used, and could be removed.
Loading history...
62
        'Member' => Member::class,
63
    ];
64
65
    /**
66
     * @var array
67
     */
68
    private static $has_many = [
0 ignored issues
show
introduced by
The private property $has_many is not used, and could be removed.
Loading history...
69
        'Details' => OrderDetail::class,
70
    ];
71
72
    /**
73
     * @var string
74
     */
75
    private static $singular_name = 'Order';
0 ignored issues
show
introduced by
The private property $singular_name is not used, and could be removed.
Loading history...
76
77
    /**
78
     * @var string
79
     */
80
    private static $plural_name = 'Orders';
0 ignored issues
show
introduced by
The private property $plural_name is not used, and could be removed.
Loading history...
81
82
    /**
83
     * @var string
84
     */
85
    private static $description = 'Orders from FoxyCart Datafeed';
0 ignored issues
show
introduced by
The private property $description is not used, and could be removed.
Loading history...
86
87
    /**
88
     * @var string
89
     */
90
    private static $default_sort = 'TransactionDate DESC, ID DESC';
0 ignored issues
show
introduced by
The private property $default_sort is not used, and could be removed.
Loading history...
91
92
    /**
93
     * @var array
94
     */
95
    private static $summary_fields = [
0 ignored issues
show
introduced by
The private property $summary_fields is not used, and could be removed.
Loading history...
96
        'OrderID',
97
        'TransactionDate.Nice',
98
        'Email',
99
        'ProductTotal.Nice',
100
        'ShippingTotal.Nice',
101
        'TaxTotal.Nice',
102
        'OrderTotal.Nice',
103
        'ReceiptLink',
104
    ];
105
106
    /**
107
     * @var array
108
     */
109
    private static $searchable_fields = [
0 ignored issues
show
introduced by
The private property $searchable_fields is not used, and could be removed.
Loading history...
110
        'OrderID',
111
        'TransactionDate' => [
112
            'field' => DateField::class,
113
            'filter' => 'PartialMatchFilter',
114
        ],
115
        'Email',
116
        'OrderTotal',
117
    ];
118
119
    /**
120
     * @var array
121
     */
122
    private static $casting = [
0 ignored issues
show
introduced by
The private property $casting is not used, and could be removed.
Loading history...
123
        'ReceiptLink' => 'HTMLVarchar',
124
    ];
125
126
    /**
127
     * @var array
128
     */
129
    private static $indexes = [
0 ignored issues
show
introduced by
The private property $indexes is not used, and could be removed.
Loading history...
130
        'OrderID' => true, // make unique
131
    ];
132
133
    /**
134
     * @var string
135
     */
136
    private static $table_name = 'FoxyOrder';
0 ignored issues
show
introduced by
The private property $table_name is not used, and could be removed.
Loading history...
137
138
    /**
139
     * @param bool $includerelations
140
     *
141
     * @return array|string
142
     */
143
    public function fieldLabels($includerelations = true)
144
    {
145
        $labels = parent::fieldLabels();
146
        $labels['StoreID'] = _t(__CLASS__ . '.StoreID', 'Store ID#');
147
        $labels['OrderID'] = _t(__CLASS__ . '.OrderID', 'Order ID#');
148
        $labels['TransactionDate'] = _t(__CLASS__ . '.TransactionDate', 'Date');
149
        $labels['TransactionDate.NiceUS'] = _t(__CLASS__ . '.TransactionDate', 'Date');
150
        $labels['Email'] = _t(__CLASS__ . '.Email', 'Email');
151
        $labels['ProductTotal.Nice'] = _t(__CLASS__ . '.ProductTotal', 'Sub Total');
152
        $labels['TaxTotal.Nice'] = _t(__CLASS__ . '.TaxTotal', 'Tax');
153
        $labels['ShippingTotal.Nice'] = _t(__CLASS__ . '.ShippingTotal', 'Shipping');
154
        $labels['OrderTotal'] = _t(__CLASS__ . '.OrderTotal', 'Total');
155
        $labels['OrderTotal.Nice'] = _t(__CLASS__ . '.OrderTotal', 'Total');
156
        $labels['ReceiptLink'] = _t(__CLASS__ . '.ReceiptLink', 'Invoice');
157
        $labels['Details.ProductID'] = _t(__CLASS__ . '.Details.ProductID', 'Product');
158
159
        return $labels;
160
    }
161
162
    /**
163
     * @return mixed
164
     */
165
    public function ReceiptLink()
166
    {
167
        return $this->getReceiptLink();
168
    }
169
170
    /**
171
     * @return mixed
172
     */
173
    public function getReceiptLink()
174
    {
175
        $obj = DBHTMLVarchar::create();
176
        $obj->setValue(
177
            '<a href="' . $this->ReceiptURL . '" target="_blank" class="cms-panel-link action external-link">view</a>'
178
        );
179
180
        return $obj;
181
    }
182
183
    /**
184
     * @return array
185
     */
186
    public function providePermissions()
187
    {
188
        return [
189
            'MANAGE_FOXY_ORDERS' => [
190
                'name' => _t(
191
                    __CLASS__ . '.PERMISSION_MANAGE_ORDERS_DESCRIPTION',
192
                    'Manage orders'
193
                ),
194
                'category' => _t(
195
                    Purchasable::class . '.PERMISSIONS_CATEGORY',
196
                    'Foxy'
197
                ),
198
                'help' => _t(
199
                    __CLASS__ . '.PERMISSION_MANAGE_ORDERS_HELP',
200
                    'Manage orders and view recipts'
201
                ),
202
                'sort' => 400,
203
            ],
204
        ];
205
    }
206
207
    /**
208
     * @param bool $member
209
     *
210
     * @return bool|int
211
     */
212
    public function canView($member = null)
213
    {
214
        return Permission::checkMember($member, 'MANAGE_FOXY_ORDERS');
215
    }
216
217
    /**
218
     * @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...
219
     *
220
     * @return bool
221
     */
222
    public function canEdit($member = null)
223
    {
224
        return false;
225
    }
226
227
    /**
228
     * @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...
229
     *
230
     * @return bool
231
     */
232
    public function canDelete($member = null)
233
    {
234
        return false;
235
    }
236
237
    /**
238
     * @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...
239
     * @param array $context
240
     *
241
     * @return bool
242
     */
243
    public function canCreate($member = null, $context = [])
244
    {
245
        return false;
246
    }
247
}
248