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::getLength()   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\Parcels;
4
5
use ShippoClient\Http\Request\CommonParameter;
6
use TurmericSpice\Container\InvalidAttributeException;
7
use TurmericSpice\ReadWriteAttributes;
8
9
/**
10
 * Parcel objects are used for creating Shipment, obtaining Rates and printing Labels,
11
 * and thus are one of the fundamental building blocks of the Shippo API.
12
 * Parcel are created with their basic dimensions and their weight.
13
 */
14
class CreateObject extends CommonParameter
15
{
16
    use ReadWriteAttributes {
17
        toArray as public __toArray;
18
    }
19
20
    /**
21
     * First dimension of the Parcel.
22
     * The length should always be the largest of the three dimensions length, width and height;
23
     * our API will automatically order them if this is not the case.
24
     * Up to six digits in front and four digits after the decimal separator are accepted.
25
     *
26
     * Required
27
     *
28
     * @return int
29
     * @throws InvalidAttributeException
30
     */
31
    public function getLength()
32
    {
33
        return $this->attributes->mustHave('length')->asInteger();
34
    }
35
36
    /**
37
     * Second dimension of the Parcel.
38
     * The width should always be the second largest of the three dimensions length, width and height;
39
     * our API will automatically order them if this is not the case.
40
     * Up to six digits in front and four digits after the decimal separator are accepted.
41
     *
42
     * Required
43
     *
44
     * @return int
45
     * @throws InvalidAttributeException
46
     */
47
    public function getWidth()
48
    {
49
        return $this->attributes->mustHave('width')->asInteger();
50
    }
51
52
    /**
53
     * Third dimension of the parcel.
54
     * The height should always be the smallest of the three dimensions length, width and height;
55
     * our API will automatically order them if this is not the case.
56
     * Up to six digits in front and four digits after the decimal separator are accepted.
57
     *
58
     * Required
59
     *
60
     * @return int
61
     * @throws InvalidAttributeException
62
     */
63
    public function getHeight()
64
    {
65
        return $this->attributes->mustHave('height')->asInteger();
66
    }
67
68
    /**
69
     * The unit used for length, width and height.
70
     *
71
     * Required
72
     *
73
     * @return string
74
     * @throws InvalidAttributeException
75
     */
76
    public function getDistanceUnit()
77
    {
78
        return $this->attributes->mustHave('distance_unit')->asString(function ($distanceUnit) {
79
            return in_array($distanceUnit, ['cm', 'in', 'ft', 'mm', 'm', 'yd'], true);
80
        });
81
    }
82
83
    /**
84
     * Weight of the parcel. Up to six digits in front and four digits after the decimal separator are accepted.
85
     *
86
     * Required
87
     *
88
     * @return int
89
     * @throws InvalidAttributeException
90
     */
91
    public function getWeight()
92
    {
93
        return $this->attributes->mustHave('weight')->asInteger();
94
    }
95
96
    /**
97
     * The unit used for weight.
98
     *
99
     * Required
100
     *
101
     * @return string
102
     * @throws InvalidAttributeException
103
     */
104
    public function getMassUnit()
105
    {
106
        return $this->attributes->mustHave('mass_unit')->asString(function ($massUnit) {
107
            return in_array($massUnit, ['g', 'oz', 'lb', 'kg'], true);
108
        });
109
    }
110
111
    /**
112
     * A parcel template is a predefined package used by one or multiple carriers.
113
     * See the table below for all available values and the corresponding tokens.
114
     * When a template is given, the parcel dimensions have to be sent, but will not be used for the Rate generation.
115
     * The dimensions below will instead be used. The parcel weight is not affected by the use of a template.
116
     *
117
     * Optional
118
     *
119
     * @return string
120
     */
121
    public function getTemplate()
122
    {
123
        return $this->attributes->mayHave('template')->asString();
124
    }
125
126
    public function toArray()
127
    {
128
        return array_filter($this->__toArray());
129
    }
130
}
131