ChargeBuilder::__construct()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 2
dl 0
loc 5
ccs 4
cts 4
cp 1
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
namespace PHPSC\PagSeguro\Purchases\Subscriptions;
3
4
use PHPSC\PagSeguro\Items\Item;
5
use PHPSC\PagSeguro\Purchases\ChargeBuilder as ChargeBuilderInterface;
6
7
/**
8
 * @author Luís Otávio Cobucci Oblonczyk <[email protected]>
9
 */
10
class ChargeBuilder implements ChargeBuilderInterface
11
{
12
    /**
13
     * @var Charge
14
     */
15
    private $charge;
16
17
    /**
18
     * @param string $code
19
     * @param Charge $charge
20
     */
21 4
    public function __construct($code, Charge $charge = null)
22
    {
23 4
        $this->charge = $charge ?: new Charge();
24 4
        $this->charge->setSubscriptionCode($code);
25 4
    }
26
27
    /**
28
     * {@inheritdoc}
29
     */
30 1
    public function addItem(Item $item)
31
    {
32 1
        $this->charge->getItems()->add($item);
33
34 1
        return $this;
35
    }
36
37
    /**
38
     * {@inheritdoc}
39
     */
40 1
    public function setReference($reference)
41
    {
42 1
        $this->charge->setReference($reference);
43
44 1
        return $this;
45
    }
46
47
    /**
48
     * {@inheritdoc}
49
     */
50 1
    public function getCharge()
51
    {
52 1
        return $this->charge;
53
    }
54
}
55