PartialRefundItem::getAmountTotal()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
/*
4
 * This file has been created by developers from BitBag.
5
 * Feel free to contact us once you face any issues or want to start
6
 * You can find more information about us on https://bitbag.io and write us
7
 * an email on [email protected].
8
 */
9
10
declare(strict_types=1);
11
12
namespace BitBag\SyliusMolliePlugin\DTO;
13
14
final class PartialRefundItem
15
{
16
    /** @var int */
17
    private $id;
18
19
    /** @var string */
20
    private $type;
21
22
    /** @var int */
23
    private $amountTotal = 0;
24
25
    /** @var int */
26
    private $amountRefunded = 0;
27
28
    /** @var int */
29
    private $quantity = 1;
30
31
    /** @var int */
32
    private $amountToRefund = 0;
33
34
    public function getId(): int
35
    {
36
        return $this->id;
37
    }
38
39
    public function setId(int $id): void
40
    {
41
        $this->id = $id;
42
    }
43
44
    public function getType(): string
45
    {
46
        return $this->type;
47
    }
48
49
    public function setType(string $type): void
50
    {
51
        $this->type = $type;
52
    }
53
54
    public function getAmountTotal(): int
55
    {
56
        return $this->amountTotal;
57
    }
58
59
    public function setAmountTotal(int $amountTotal): void
60
    {
61
        $this->amountTotal = $amountTotal;
62
    }
63
64
    public function getAmountRefunded(): int
65
    {
66
        return $this->amountRefunded;
67
    }
68
69
    public function setAmountRefunded(int $amountRefunded): void
70
    {
71
        $this->amountRefunded += $amountRefunded;
72
    }
73
74
    public function getQuantity(): int
75
    {
76
        return $this->quantity;
77
    }
78
79
    public function setQuantity(int $quantity): void
80
    {
81
        $this->quantity = $quantity;
82
    }
83
84
    public function getAvailableAmountToRefund(): int
85
    {
86
        return $this->getAmountTotal() - $this->getAmountRefunded() - $this->getAmountToRefund();
87
    }
88
89
    public function setAmountToRefund(int $amount): int
90
    {
91
        $value = $this->getAvailableAmountToRefund() - $amount;
92
93
        if ($value < 0) {
94
            $this->amountToRefund = $this->getAvailableAmountToRefund();
95
96
            return abs($value);
0 ignored issues
show
Bug Best Practice introduced by
The expression return abs($value) could return the type double which is incompatible with the type-hinted return integer. Consider adding an additional type-check to rule them out.
Loading history...
97
        }
98
99
        $this->amountToRefund = $amount;
100
101
        return 0;
102
    }
103
104
    public function getAmountToRefund(): int
105
    {
106
        return $this->amountToRefund;
107
    }
108
}
109