GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

CreateObject::getAddressReturn()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace ShippoClient\Http\Request\Shipments;
4
5
use ShippoClient\Http\Request\CommonParameter;
6
use TurmericSpice\Container\InvalidAttributeException;
7
use TurmericSpice\ReadWriteAttributes;
8
9
/**
10
 * The heart of the Shippo API, a Shipment is made up of "to" and "from" Address and the Parcel to be shipped.
11
 * Once created, a Shipment object can be used to retrieve shipping Rates and purchase a shipping Label.
12
 */
13
class CreateObject extends CommonParameter
14
{
15
    use ReadWriteAttributes {
16
        toArray as public __toArray;
17
    }
18
19
    const OBJECT_PURPOSE_QUOTE = 'QUOTE';
20
    const OBJECT_PURPOSE_PURCHASE = 'PURCHASE';
21
    const SUBMISSION_TYPE_DROPOFF = 'DROPOFF';
22
    const SUBMISSION_TYPE_PICKUP = 'PICKUP';
23
24
    /**
25
     * Quote Shipment can only be used to obtain quote Rates;
26
     * at the same time, they accept any valid or completed Address object.
27
     * Purchase Shipment can be used to obtain Rates and purchase Labels,
28
     * but only accept purchase Address that have been fully entered.
29
     *
30
     * Required
31
     *
32
     * @return string
33
     * @throws InvalidAttributeException
34
     */
35 View Code Duplication
    public function getObjectPurpose()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
36
    {
37
        $allowed = [static::OBJECT_PURPOSE_QUOTE, static::OBJECT_PURPOSE_PURCHASE];
38
39
        return $this->attributes->mustHave('object_purpose')->asString(function ($value) use ($allowed) {
40
            return in_array($value, $allowed, true);
41
        });
42
    }
43
44
    /**
45
     * ID of the Address object that should be used as sender Address.
46
     *
47
     * Required
48
     *
49
     * @return string
50
     * @throws InvalidAttributeException
51
     */
52
    public function getAddressFrom()
53
    {
54
        return $this->attributes->mustHave('address_from')->asString();
55
    }
56
57
    /**
58
     * ID of the Address object that should be used as recipient Address.
59
     *
60
     * Required
61
     *
62
     * @return string
63
     * @throws InvalidAttributeException
64
     */
65
    public function getAddressTo()
66
    {
67
        return $this->attributes->mustHave('address_to')->asString();
68
    }
69
70
    /**
71
     * ID of the Parcel object to be shipped.
72
     *
73
     * Required
74
     *
75
     * @return string
76
     * @throws InvalidAttributeException
77
     */
78
    public function getParcel()
79
    {
80
        return $this->attributes->mustHave('parcel')->asString();
81
    }
82
83
    /**
84
     * Indicates whether the parcel will be dropped off at a carrier location or will be picked up.
85
     * Selecting 'PICKUP' does not request a carrier pickup.
86
     * A pickup always needs to be requested separately.
87
     *
88
     * Optional, defaults to DROPOFF
89
     *
90
     * @return string
91
     * @throws InvalidAttributeException
92
     */
93
    public function getSubmissionType()
94
    {
95
        $allowed = [static::SUBMISSION_TYPE_DROPOFF, static::SUBMISSION_TYPE_PICKUP];
96
97
        $submission_type = $this->attributes->mayHave('submission_type');
98
        if ($submission_type->value() === null) {
99
            return static::SUBMISSION_TYPE_DROPOFF;
100
        }
101
102
        return $submission_type->asString(function ($value) use ($allowed) {
103
            return in_array($value, $allowed, true);
104
        });
105
    }
106
107
    /**
108
     * ID of the Transaction object of the outbound shipment.
109
     * This field triggers the creation of a scan-based return shipments.
110
     * See the Create a return shipment section for more details.
111
     *
112
     * Required for return labels
113
     *
114
     * @return string
115
     */
116
    public function getReturnOf()
117
    {
118
        return $this->attributes->mayHave('return_of')->asString();
119
    }
120
121
    /**
122
     * Desired pickup date. Must be in the format "2014-01-18T00:35:03.463Z" (ISO 8601 date).
123
     * Please note that for some carriers, not all pickup dates are available.
124
     * The API will return the corresponding error message if not available.
125
     * If no pickup_date is given, the value will default to tomorrow's date
126
     * (including Saturday or Sunday, which can lead to no carrier availability).
127
     *
128
     * Required if submission_type is 'PICKUP'. Defaults to current date (UTC) for 'DROPOFF'
129
     *
130
     * @return string
131
     * @throws InvalidAttributeException
132
     */
133
    public function getSubmissionDate()
134
    {
135
        $isIOS8601Format = function ($datetime) {
136
            // this pattern is not strict but is sufficient
137
            return preg_match('/^(\d{4}-\d{2}-\d{2}|\d{8})[t|T]\d{2}:\d{2}:\d{2}([,|\.]\d+[z|Z]|\+\d+)$/', $datetime);
138
        };
139
140
        $submission_date = $this->attributes->mayHave('submission_date');
141
        if ($submission_date->value() === null) {
142
            if ($this->getSubmissionType() !== static::SUBMISSION_TYPE_PICKUP) {
143
                return null;
144
            }
145
146
            return (new \DateTime('now', new \DateTimeZone('UTC')))->format(\DateTime::ISO8601);
147
        }
148
149
        return $submission_date->asString($isIOS8601Format);
150
    }
151
152
    /**
153
     * ID of the Address object where the shipment will be sent back to if it is not delivered
154
     * (Only available for UPS, USPS, and Fedex shipments).
155
     * If this field is not set, your shipments will be returned to the address_form.
156
     *
157
     * Optional
158
     *
159
     * @return string
160
     */
161
    public function getAddressReturn()
162
    {
163
        return $this->attributes->mayHave('address_return')->asString();
164
    }
165
166
    /**
167
     * ID of the Customs Declarations object for an international shipment.
168
     *
169
     * Optional
170
     *
171
     * @return string
172
     */
173
    public function getCustomsDeclaration()
174
    {
175
        return $this->attributes->mayHave('customs_declaration')->asString();
176
    }
177
178
    /**
179
     * Total Parcel value to be insured.
180
     * Please note that you need to specify the "insurance_currency" as well as the "insurance_content"
181
     * (via the extra field below, if your package content is not general cargo) as well.
182
     *
183
     * Optional
184
     *
185
     * @return float
186
     */
187
    public function getInsuranceAmount()
188
    {
189
        return $this->attributes->mayHave('insurance_amount')->asFloat();
190
    }
191
192
    /**
193
     * Currency used for insurance_amount.
194
     * The official ISO 4217 currency codes are used, e.g. "USD" or "EUR".
195
     *
196
     * Required if insurance_amount is set
197
     *
198
     * @return string
199
     * @throws InvalidAttributeException
200
     */
201
    public function getInsuranceCurrency()
202
    {
203
        if ($this->attributes->mayHave('insurance_amount')->value() === null) {
204
            return $this->attributes->mayHave('insurance_currency')->asString();
205
        }
206
207
        return $this->attributes->mustHave('insurance_currency')->asString();
208
    }
209
210
    /**
211
     * An array of extra services to be requested.
212
     * The following services are currently available. We are continuously adding new ones.
213
     *     - signature_confirmation (string, "standard" for standard signature confirmation, "adult" for adult signature)
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 121 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
214
     *     - insurance_content (string, specify package content for insurance)
215
     *     - saturday_delivery (boolean, marks shipment as to be delivered on a Saturday)
216
     *     - bypass_address_validation (boolean, bypassed address validation, if applicable)
217
     *     - use_manifests (boolean, shipment to be linked with a manifest (Canada Post only), if applicable)
218
     *     - saturday_delivery (boolean, marks shipment as to be delivered on a Saturday. Available for UPS and FedEx.)
219
     *     - bypass_address_validation (boolean, bypassed address validation. Available for USPS, FedEx and UPS.)
220
     *     - request_retail_rates (boolean, request retail/list rates. Available for FedEx.)
221
     *     - use_manifests (boolean, shipment to be linked with a manifest (Canada Post only), if applicable)
222
     *
223
     * Optional
224
     *
225
     * @return array
226
     */
227
    public function getExtra()
228
    {
229
        return $this->attributes->mayHave('extra')->asArray();
230
    }
231
232
    /**
233
     * Optional text to be printed on the shipping label.
234
     *
235
     * Optional
236
     *
237
     * @return string
238
     */
239
    public function getReference1()
240
    {
241
        return $this->attributes->mayHave('reference_1')->asString();
242
    }
243
244
    /**
245
     * Optional text to be printed on the shipping label.
246
     *
247
     * Optional
248
     *
249
     * @return string
250
     */
251
    public function getReference2()
252
    {
253
        return $this->attributes->mayHave('reference_2')->asString();
254
    }
255
256
    /**
257
     * An array of object_ids of the carrier account objects to be used for getting shipping rates for this shipment.
258
     * If no carrier account object_ids are set in this field,
259
     * Shippo will attempt to generate rates using all the carrier accounts that have the 'active' field set.
260
     *
261
     * @return string
262
     */
263
    public function getCarrierAccounts()
264
    {
265
        return $this->attributes->mayHave('carrier_accounts')->asArray();
266
    }
267
268
    public function toArray()
269
    {
270
        return array_filter($this->__toArray());
271
    }
272
}
273