Dimension::height()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 1
1
<?php
2
3
namespace OceanApplications\Postmen\Models;
4
5
class Dimension extends Model
6
{
7
    public $width;
8
    public $height;
9
    public $depth;
10
    public $unit;
11
12
    public function __construct($width = null, $height = null, $depth = null, $unit = null)
13
    {
14
        if ($width != null && $height != null && $depth != null && $unit != null) {
15
            $this->width($width);
16
            $this->height($height);
17
            $this->depth($depth);
18
            $this->unit($unit);
19
        }
20
    }
21
22
    /**
23
     * @param $value
24
     *
25
     * @return $this
26
     */
27
    public function width($value)
28
    {
29
        $this->width = floatval($value);
30
31
        return $this;
32
    }
33
34
    /**
35
     * @param $value
36
     *
37
     * @return $this
38
     */
39
    public function height($value)
40
    {
41
        $this->height = floatval($value);
42
43
        return $this;
44
    }
45
46
    /**
47
     * @param $value
48
     *
49
     * @return $this
50
     */
51
    public function depth($value)
52
    {
53
        $this->depth = floatval($value);
54
55
        return $this;
56
    }
57
58
    /**
59
     * @param $value in or cm
60
     *
61
     * @throws \Exception
62
     *
63
     * @return $this
64
     */
65
    public function unit($value)
66
    {
67
        if ($value == 'in' || $value = 'cm') {
68
            $this->unit = $value;
69
        } else {
70
            $error = 'Unit must be in or cm';
71
            throw new \Exception($error);
72
        }
73
74
        return $this;
75
    }
76
}
77