IncomeServiceItem   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 16
c 0
b 0
f 0
dl 0
loc 55
rs 10
wmc 6

6 Methods

Rating   Name   Duplication   Size   Complexity  
A getAmount() 0 3 1
A getQuantity() 0 3 1
A jsonSerialize() 0 6 1
A __construct() 0 5 1
A getTotalAmount() 0 4 1
A getName() 0 3 1
1
<?php
2
declare(strict_types=1);
3
4
namespace Shoman4eg\Nalog\DTO;
5
6
use Brick\Math\BigDecimal;
7
8
/**
9
 * @author Artem Dubinin <[email protected]>
10
 */
11
final class IncomeServiceItem implements \JsonSerializable
12
{
13
    private string $name;
14
15
    /** @var float|int|string */
16
    private $amount;
17
18
    /** @var float|int */
19
    private $quantity;
20
21
    /**
22
     * @param float|int|string $amount
23
     * @param float|int        $quantity
24
     */
25
    public function __construct(string $name, $amount, $quantity)
26
    {
27
        $this->name = $name;
28
        $this->amount = $amount;
29
        $this->quantity = $quantity;
30
    }
31
32
    public function jsonSerialize(): array
33
    {
34
        return [
35
            'name' => $this->name,
36
            'amount' => $this->amount,
37
            'quantity' => $this->quantity,
38
        ];
39
    }
40
41
    public function getName(): string
42
    {
43
        return $this->name;
44
    }
45
46
    /**
47
     * @return float|int|string
48
     */
49
    public function getAmount()
50
    {
51
        return $this->amount;
52
    }
53
54
    /**
55
     * @return float|int
56
     */
57
    public function getQuantity()
58
    {
59
        return $this->quantity;
60
    }
61
62
    public function getTotalAmount(): BigDecimal
63
    {
64
        return BigDecimal::of($this->amount)
0 ignored issues
show
Bug Best Practice introduced by
The expression return Brick\Math\BigDec...liedBy($this->quantity) could return the type Brick\Math\BigInteger|Brick\Math\BigRational which is incompatible with the type-hinted return Brick\Math\BigDecimal. Consider adding an additional type-check to rule them out.
Loading history...
65
            ->multipliedBy($this->quantity)
66
        ;
67
    }
68
}
69