Shipping::setType()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 1
dl 0
loc 8
ccs 5
cts 5
cp 1
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
namespace PHPSC\PagSeguro\Shipping;
3
4
use InvalidArgumentException;
5
use PHPSC\PagSeguro\Customer\Address;
6
use PHPSC\PagSeguro\SerializerTrait;
7
use JMS\Serializer\Annotation as Serializer;
8
9
/**
10
 * @Serializer\AccessType("public_method")
11
 * @Serializer\ReadOnly
12
 * @Serializer\XmlRoot("shipping")
13
 *
14
 * @author Luís Otávio Cobucci Oblonczyk <[email protected]>
15
 */
16
class Shipping
17
{
18
    use SerializerTrait;
19
20
    /**
21
     * @Serializer\Type("integer")
22
     *
23
     * @var int
24
     */
25
    private $type;
26
27
    /**
28
     * @Serializer\Type("PHPSC\PagSeguro\Customer\Address")
29
     *
30
     * @var Address
31
     */
32
    private $address;
33
34
    /**
35
     * @Serializer\XmlElement(cdata=false)
36
     *
37
     * @var float
38
     */
39
    private $cost;
40
41
    /**
42
     * @param int $type
43
     * @param Address $address
44
     * @param float $cost
45
     */
46 12
    public function __construct($type, Address $address = null, $cost = null)
47
    {
48 12
        $this->setType($type);
49 11
        $this->address = $address;
50
51 11
        if ($cost !== null) {
52 6
            $this->cost = (float) $cost;
53
        }
54 11
    }
55
56
    /**
57
     * @return number
58
     */
59 3
    public function getType()
60
    {
61 3
        return $this->type;
62
    }
63
64 12
    protected function setType($type)
65
    {
66 12
        if (!Type::isValid($type)) {
67 1
            throw new InvalidArgumentException('Invalid shipping type informed');
68
        }
69
70 11
        $this->type = (int) $type;
71 11
    }
72
73
    /**
74
     * @return Address
75
     */
76 3
    public function getAddress()
77
    {
78 3
        return $this->address;
79
    }
80
81
    /**
82
     * @return string
83
     */
84 3
    public function getCost()
85
    {
86 3
        return $this->formatAmount($this->cost);
87
    }
88
}
89