Shipping   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 73
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 2
dl 0
loc 73
ccs 17
cts 17
cp 1
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 2
A getType() 0 4 1
A setType() 0 8 2
A getAddress() 0 4 1
A getCost() 0 4 1
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