Completed
Push — master ( 854615...6f1a30 )
by Andrii
03:22
created

Charge::getSum()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
/**
3
 * PHP Billing Library
4
 *
5
 * @link      https://github.com/hiqdev/php-billing
6
 * @package   php-billing
7
 * @license   BSD-3-Clause
8
 * @copyright Copyright (c) 2017, HiQDev (http://hiqdev.com/)
9
 */
10
11
namespace hiqdev\php\billing\charge;
12
13
use hiqdev\php\billing\action\ActionInterface;
14
use hiqdev\php\billing\target\TargetInterface;
15
use hiqdev\php\billing\type\TypeInterface;
16
use hiqdev\php\units\QuantityInterface;
17
use Money\Money;
18
19
/**
20
 * Charge.
21
 *
22
 * [[Action]] is charged with a number of [[Charge]]s.
23
 *
24
 * @author Andrii Vasyliev <[email protected]>
25
 */
26
class Charge implements \JsonSerializable
27
{
28
    /**
29
     * @var int
30
     */
31
    protected $id;
32
33
    /**
34
     * @var ActionInterface
35
     */
36
    protected $action;
37
38
    /**
39
     * @var TypeInterface
40
     */
41
    protected $type;
42
43
    /**
44
     * @var TargetInterface
45
     */
46
    protected $target;
47
48
    /**
49
     * @var QuantityInterface
50
     */
51
    protected $usage;
52
53
    /**
54
     * @var Money
55
     */
56
    protected $sum;
57
58 3
    public function __construct(
59
                            $id,
60
        ActionInterface     $action,
61
        TypeInterface       $type,
62
        TargetInterface     $target,
63
        QuantityInterface   $usage,
64
        Money               $sum
65
    ) {
66 3
        $this->id       = $id;
67 3
        $this->action   = $action;
68 3
        $this->type     = $type;
69 3
        $this->target   = $target;
70 3
        $this->usage    = $usage;
71 3
        $this->sum      = $sum;
72 3
    }
73
74
    public function getId()
75
    {
76
        return $this->id;
77
    }
78
79 3
    public function getAction()
80
    {
81 3
        return $this->action;
82
    }
83
84 3
    public function getTarget()
85
    {
86 3
        return $this->target;
87
    }
88
89 3
    public function getType()
90
    {
91 3
        return $this->type;
92
    }
93
94 3
    public function getUsage()
95
    {
96 3
        return $this->usage;
97
    }
98
99 3
    public function getSum()
100
    {
101 3
        return $this->sum;
102
    }
103
104
    public function getPrice()
105
    {
106
        return $this->sum->divide($this->usage);
0 ignored issues
show
Documentation introduced by
$this->usage is of type object<hiqdev\php\units\QuantityInterface>, but the function expects a double|integer|string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
107
    }
108
109
    public function jsonSerialize()
110
    {
111
        return get_object_vars($this);
112
    }
113
}
114