Volume::setWeight()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 5
rs 10
1
<?php
2
3
namespace MelhorEnvio\Resources\Shipment;
4
5
use MelhorEnvio\Concerns\Arrayable;
6
use MelhorEnvio\Validations\Number;
7
use InvalidArgumentException;
8
9
abstract class Volume implements Arrayable
10
{
11
    /**
12
     * @var int|float
13
     */
14
    protected $height;
15
16
    /**
17
     * @var int|float
18
     */
19
    protected $width;
20
21
    /**
22
     * @var int|float
23
     */
24
    protected $length;
25
26
    /**
27
     * @var int|float
28
     */
29
    protected $weight;
30
31
    /**
32
     * @return int|float
33
     */
34
    public function getWeight()
35
    {
36
        return $this->weight;
37
    }
38
39
    /**
40
     * @param int|float $weight
41
     */
42
    public function setWeight($weight)
43
    {
44
        $this->validateNumericArgument($weight, 'weight');
45
46
        $this->weight = $weight;
47
    }
48
49
    /**
50
     * @return int|float
51
     */
52
    public function getLength()
53
    {
54
        return $this->length;
55
    }
56
57
    /**
58
     * @param int|float $length
59
     */
60
    public function setLength($length)
61
    {
62
        $this->validateNumericArgument($length, 'length');
63
64
        $this->length = $length;
65
    }
66
67
    /**
68
     * @return int|float
69
     */
70
    public function getWidth()
71
    {
72
        return $this->width;
73
    }
74
75
    /**
76
     * @param int|float $width
77
     */
78
    public function setWidth($width)
79
    {
80
        $this->validateNumericArgument($width, 'width');
81
82
        $this->width = $width;
83
    }
84
85
    /**
86
     * @return int|float
87
     */
88
    public function getHeight()
89
    {
90
        return $this->height;
91
    }
92
93
    /**
94
     * @param int|float $height
95
     */
96
    public function setHeight($height)
97
    {
98
        $this->validateNumericArgument($height, 'height');
99
100
        $this->height = $height;
101
    }
102
103
    /**
104
     * @param int|float $number
105
     * @param string $argument
106
     */
107
    protected function validateNumericArgument($number, $argument)
108
    {
109
        if (! Number::isPositive($number)) {
110
            throw new InvalidArgumentException($argument);
111
        }
112
    }
113
114
    /**
115
     * @return bool
116
     */
117
    public function isValid()
118
    {
119
        return ! empty($this->getHeight())
120
            && ! empty($this->getWidth())
121
            && ! empty($this->getLength())
122
            && ! empty($this->getWeight());
123
    }
124
}
125