Package::setWeight()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 15
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 10
c 1
b 0
f 0
nc 3
nop 1
dl 0
loc 15
rs 9.4285
1
<?php
2
3
/**
4
 *
5
 */
6
namespace SimpleUPS;
7
8
/**
9
 * @internal
10
 * @since 1.0
11
 */
12
class Package extends \SimpleUPS\Model
13
{
14
    private
15
        /* @var Weight $weight */
16
        $weight;
17
18
    /**
19
     * Set the weight of this package
20
     *
21
     * @param Float|Weight $weight
22
     *
23
     * @return Package
24
     */
25
    public function setWeight($weight)
26
    {
27
        if (is_numeric($weight)) {
28
            $weightObject = new Weight();
29
            $weightObject->setWeight($weight);
30
            $weight = $weightObject;
31
        } else {
32
            if (!($weight instanceOf Weight)) {
33
                throw new \Exception('Weight must either be numeric or an instance of \SimpleUPS\Weight');
34
            }
35
        }
36
37
        $this->weight = $weight;
38
        return $this;
39
    }
40
41
    /**
42
     * Get weight of package
43
     * @return Weight
44
     */
45
    public function getWeight()
46
    {
47
        return $this->weight;
48
    }
49
}