Weight   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 1

Importance

Changes 0
Metric Value
wmc 7
lcom 2
cbo 1
dl 0
loc 42
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 3
A unit() 0 11 3
A value() 0 6 1
1
<?php
2
3
namespace OceanApplications\Postmen\Models;
4
5
class Weight extends Model
6
{
7
    public $unit;
8
    public $value;
9
10
    public function __construct($value = null, $unit = null)
11
    {
12
        if ($value != null && $unit != null) {
13
            $this->value($value);
14
            $this->unit($unit);
15
        }
16
    }
17
18
    /**
19
     * @param $value
20
     *
21
     * @return $this
22
     */
23
    public function unit($value)
24
    {
25
        if ($value == 'lb' || $value == 'kg') {
26
            $this->unit = $value;
27
        } else {
28
            $error = 'Unit must be lb or kg';
29
            throw new \Exception($error);
30
        }
31
32
        return $this;
33
    }
34
35
    /**
36
     * @param init $value
37
     *
38
     * @return $this
39
     */
40
    public function value($value)
41
    {
42
        $this->value = floatval($value);
43
44
        return $this;
45
    }
46
}
47