Completed
Push — master ( b7e254...bcf326 )
by
unknown
09:07
created

PartialRefundItem   A

Complexity

Total Complexity 14

Size/Duplication

Total Lines 93
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 14
eloc 25
c 1
b 0
f 0
dl 0
loc 93
rs 10

13 Methods

Rating   Name   Duplication   Size   Complexity  
A setAmountRefunded() 0 3 1
A getAmountTotal() 0 3 1
A setAmountTotal() 0 3 1
A getType() 0 3 1
A getQuantity() 0 3 1
A setType() 0 3 1
A getId() 0 3 1
A setId() 0 3 1
A setQuantity() 0 3 1
A getAmountRefunded() 0 3 1
A getAvailableAmountToRefund() 0 3 1
A getAmountToRefund() 0 3 1
A setAmountToRefund() 0 13 2
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
 * another great project.
7
 * You can find more information about us on https://bitbag.shop and write us
8
 * an email on [email protected].
9
 */
10
11
declare(strict_types=1);
12
13
namespace BitBag\SyliusMolliePlugin\DTO;
14
15
final class PartialRefundItem
16
{
17
    /** @var int */
18
    private $id;
19
20
    /** @var string */
21
    private $type;
22
23
    /** @var int */
24
    private $amountTotal = 0;
25
26
    /** @var int */
27
    private $amountRefunded = 0;
28
29
    /** @var int */
30
    private $quantity = 1;
31
32
    /** @var int */
33
    private $amountToRefund = 0;
34
35
    public function getId(): int
36
    {
37
        return $this->id;
38
    }
39
40
    public function setId(int $id): void
41
    {
42
        $this->id = $id;
43
    }
44
45
    public function getType(): string
46
    {
47
        return $this->type;
48
    }
49
50
    public function setType(string $type): void
51
    {
52
        $this->type = $type;
53
    }
54
55
    public function getAmountTotal(): int
56
    {
57
        return $this->amountTotal;
58
    }
59
60
    public function setAmountTotal(int $amountTotal): void
61
    {
62
        $this->amountTotal = $amountTotal;
63
    }
64
65
    public function getAmountRefunded(): int
66
    {
67
        return $this->amountRefunded;
68
    }
69
70
    public function setAmountRefunded(int $amountRefunded): void
71
    {
72
        $this->amountRefunded += $amountRefunded;
73
    }
74
75
    public function getQuantity(): int
76
    {
77
        return $this->quantity;
78
    }
79
80
    public function setQuantity(int $quantity): void
81
    {
82
        $this->quantity = $quantity;
83
    }
84
85
    public function getAvailableAmountToRefund(): int
86
    {
87
        return $this->getAmountTotal() - $this->getAmountRefunded() - $this->getAmountToRefund();
88
    }
89
90
    public function setAmountToRefund(int $amount): int
91
    {
92
        $value = $this->getAvailableAmountToRefund() - $amount;
93
94
        if ($value < 0) {
95
            $this->amountToRefund = $this->getAvailableAmountToRefund();
96
97
            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...
98
        }
99
100
        $this->amountToRefund = $amount;
101
102
        return 0;
103
    }
104
105
    public function getAmountToRefund()
106
    {
107
        return $this->amountToRefund;
108
    }
109
}
110