Passed
Branch 1.0 (badbbc)
by Morven
01:40
created

Parcel   A

Complexity

Total Complexity 26

Size/Duplication

Total Lines 256
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 256
rs 10
c 0
b 0
f 0
wmc 26

25 Methods

Rating   Name   Duplication   Size   Complexity  
A setLongditude() 0 4 1
A getWeight() 0 3 1
A setCountry() 0 4 1
A getAddress() 0 3 1
A getHeight() 0 3 1
A getLongditude() 0 3 1
A setDepth() 0 4 1
A getItems() 0 3 1
A __construct() 0 4 1
A getWidth() 0 3 1
A setWeight() 0 4 1
A setWidth() 0 4 1
A getValue() 0 3 1
A setItems() 0 4 1
A setAddress() 0 4 1
A getVolume() 0 3 1
A setRegion() 0 4 1
A setValue() 0 5 1
A getPostageOptions() 0 11 2
A setHeight() 0 4 1
A getRegion() 0 3 1
A setLatitude() 0 4 1
A getLatitude() 0 3 1
A getDepth() 0 3 1
A getCountry() 0 3 1
1
<?php
2
3
namespace SilverCommerce\Postage\Helpers;
4
5
use SilverStripe\ORM\ArrayList;
6
use SilverStripe\ORM\DataObject;
7
use SilverStripe\SiteConfig\SiteConfig;
8
use SilverStripe\Core\Injector\Injectable;
9
10
/**
11
 * A parcel is a generic object that can be handed to the postage calculator
12
 * to find the best applicable shipping rate.
13
 * 
14
 * NOTE Thanks to SilverShop for this idea!
15
 * 
16
 */
17
class Parcel
18
{
19
    use Injectable;
20
21
    /**
22
     * Total width of the package
23
     * 
24
     * @var int
25
     */
26
    protected $width  = 0;
27
28
    public function getWidth()
29
    {
30
        return $this->width;
31
    }
32
33
    public function setWidth($width)
34
    {
35
        $this->width = $width;
36
        return $this;
37
    }
38
39
    /**
40
     * Total height of the package
41
     * 
42
     * @var int
43
     */
44
    protected $height = 0;
45
46
    public function getHeight()
47
    {
48
        return $this->height;
49
    }
50
51
    public function setHeight($height)
52
    {
53
        $this->height = $height;
54
        return $this;
55
    }
56
57
    /**
58
     * Total depth of the package
59
     * 
60
     * @var int
61
     */
62
    protected $depth = 0;
63
64
    public function getDepth()
65
    {
66
        return $this->depth;
67
    }
68
69
    public function setDepth($depth)
70
    {
71
        $this->depth = $depth;
72
        return $this;
73
    }
74
75
    /**
76
     * Total weight of the package
77
     * 
78
     * @var int
79
     */
80
    protected $weight = 0;
81
82
    public function getWeight()
83
    {
84
        return $this->weight;
85
    }
86
87
    public function setWeight($weight)
88
    {
89
        $this->weight = $weight;
90
        return $this;
91
    }
92
93
    /**
94
     * Total number of items in the package
95
     * 
96
     * @var int
97
     */
98
    protected $items = 0;
99
100
    public function getItems()
101
    {
102
        return $this->items;
103
    }
104
105
    public function setItems($items)
106
    {
107
        $this->items = $items;
108
        return $this;
109
    }
110
111
    /**
112
     * The total monitary value of this parcel
113
     * 
114
     * @var float
115
     */
116
    protected $value = 0;
117
118
    /**
119
     * Get the value of value
120
     */ 
121
    public function getValue()
122
    {
123
        return $this->value;
124
    }
125
126
    /**
127
     * Set the value of value
128
     *
129
     * @return  self
130
     */ 
131
    public function setValue($value)
132
    {
133
        $this->value = $value;
134
135
        return $this;
136
    }
137
138
    /**
139
     * The country this parcel is to be delivered to
140
     * 
141
     * Expects the ISO-3166 2 character country code
142
     * 
143
     * @var string
144
     */
145
    protected $country = null;
146
147
    public function getCountry()
148
    {
149
        return $this->country;
150
    }
151
152
    public function setCountry($country)
153
    {
154
        $this->country = $country;
155
        return $this;
156
    }
157
158
    /**
159
     * The region witin a country this parcel is to be delivered to
160
     * 
161
     * Expects the ISO-3166-2 3 character "subdivision" code
162
     * 
163
     * @var string
164
     */
165
    protected $region = null;
166
167
    public function getRegion()
168
    {
169
        return $this->region;
170
    }
171
172
    public function setRegion($region)
173
    {
174
        $this->region = $region;
175
        return $this;
176
    }
177
178
    /**
179
     * Optional full address that this parcel needs to be delivered to
180
     * 
181
     * @var string
182
     */
183
    protected $address = null;
184
185
    public function getAddress()
186
    {
187
        return $this->address;
188
    }
189
190
    public function setAddress(string $address)
191
    {
192
        $this->address = $address;
193
        return $this;
194
    }
195
196
    /**
197
     * Optional latitude of the address that this parcel needs to be delivered
198
     * to (useful for things like distance based shipping using geo-location)
199
     * 
200
     * @var string
201
     */
202
    protected $latitude = null;
203
204
    public function getLatitude()
205
    {
206
        return $this->latitude;
207
    }
208
209
    public function setLatitude(string $latitude)
210
    {
211
        $this->latitude = $latitude;
212
        return $this;
213
    }
214
215
    /**
216
     * Optional longditude of the address that this parcel needs to be delivered
217
     * to (useful for things like distance based shipping using geo-location)
218
     * 
219
     * @var string
220
     */
221
    protected $longditude = null;
222
223
    public function getLongditude()
224
    {
225
        return $this->longditude;
226
    }
227
228
    public function setLongditude(string $longditude)
229
    {
230
        $this->longditude = $longditude;
231
        return $this;
232
    }
233
234
    /**
235
     * Calculate total volume
236
     * 
237
     * @var int
238
     */
239
    public function getVolume()
240
    {
241
        return $this->height * $this->width * $this->depth;
242
    }
243
244
    /**
245
     * Initialise this Package
246
     * 
247
     * @param $country Set the country for this Parcel
0 ignored issues
show
Bug introduced by
The type SilverCommerce\Postage\Helpers\Set 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...
248
     * @param $region Set the region for this parcel
249
     */
250
    public function __construct($country, $region)
251
    {
252
        $this->country = $country;
253
        $this->region = $region;
254
    }
255
256
    /**
257
     * Generate a list of availabe postage options, from the current
258
     * available Postage Types.
259
     *
260
     * @return ArrayList
261
     */
262
    public function getPostageOptions()
263
    {
264
        $config = SiteConfig::current_site_config();
265
        $types = $config->PostageTypes()->filter("Enabled", true);
266
        $options = ArrayList::create();
267
268
        foreach ($types as $type) {
269
            $options->merge($type->getPossiblePostage($this));
270
        }
271
272
        return $options;
273
    }
274
}