Passed
Push — master ( eff4fb...57c190 )
by Sam
07:38
created

AbstractProduct::setImage()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 3
nc 2
nop 1
dl 0
loc 9
ccs 4
cts 4
cp 1
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Application\Model;
6
7
use Application\Traits\HasCode;
8
use Application\Traits\HasProductType;
9
use Application\Traits\HasRichTextDescription;
10
use Doctrine\ORM\Mapping as ORM;
11
use Ecodev\Felix\Model\Traits\HasInternalRemarks;
12
use Ecodev\Felix\Model\Traits\HasName;
13
use GraphQL\Doctrine\Annotation as API;
14
use Money\Money;
15
16
/**
17
 * An item that can be booked by a user.
18
 *
19
 * @ORM\MappedSuperclass
20
 */
21
abstract class AbstractProduct extends AbstractModel
22
{
23
    use HasCode;
24
    use HasInternalRemarks;
25
    use HasName;
26
    use HasProductType;
27
    use HasRichTextDescription;
28
29
    /**
30
     * @ORM\Column(type="CHF", options={"default" = "0"})
31
     */
32
    private Money $pricePerUnitCHF;
33
34
    /**
35
     * @ORM\Column(type="EUR", options={"default" = "0"})
36
     */
37
    private Money $pricePerUnitEUR;
38
39
    /**
40
     * @ORM\Column(type="boolean", options={"default" = 1})
41
     */
42
    private bool $isActive = true;
43
44
    /**
45
     * @ORM\OneToOne(targetEntity="Image", orphanRemoval=true)
46
     * @ORM\JoinColumn(name="image_id", referencedColumnName="id", onDelete="CASCADE")
47
     */
48
    private ?Image $image = null;
49
50
    /**
51
     * @ORM\OneToOne(targetEntity="Image", orphanRemoval=true)
52
     * @ORM\JoinColumn(name="illustration_id", referencedColumnName="id", onDelete="CASCADE")
53
     */
54
    private ?Image $illustration = null;
55
56 28
    public function __construct(string $name = '')
57
    {
58 28
        $this->setName($name);
59 28
        $this->pricePerUnitCHF = Money::CHF(0);
60 28
        $this->pricePerUnitEUR = Money::EUR(0);
61
    }
62
63
    /**
64
     * @API\Field(type="CHF")
65
     */
66 11
    public function getPricePerUnitCHF(): Money
67
    {
68 11
        return $this->pricePerUnitCHF;
69
    }
70
71
    /**
72
     * @API\Input(type="CHF")
73
     */
74 8
    public function setPricePerUnitCHF(Money $pricePerUnitCHF): void
75
    {
76 8
        $this->pricePerUnitCHF = $pricePerUnitCHF;
77
    }
78
79
    /**
80
     * @API\Field(type="EUR")
81
     */
82 1
    public function getPricePerUnitEUR(): Money
83
    {
84 1
        return $this->pricePerUnitEUR;
85
    }
86
87
    /**
88
     * @API\Input(type="EUR")
89
     */
90 8
    public function setPricePerUnitEUR(Money $pricePerUnitEUR): void
91
    {
92 8
        $this->pricePerUnitEUR = $pricePerUnitEUR;
93
    }
94
95
    /**
96
     * Whether this product can be bought.
97
     */
98
    public function isActive(): bool
99
    {
100
        return $this->isActive;
101
    }
102
103
    /**
104
     * Whether this product can be bought.
105
     */
106
    public function setIsActive(bool $isActive): void
107
    {
108
        $this->isActive = $isActive;
109
    }
110
111 1
    public function getImage(): ?Image
112
    {
113 1
        return $this->image;
114
    }
115
116 1
    public function setImage(?Image $image): void
117
    {
118
        // We must trigger lazy loading, otherwise Doctrine will seriously
119
        // mess up lifecycle callbacks and delete unrelated image on disk
120 1
        if ($this->image) {
121 1
            $this->image->getFilename();
122
        }
123
124 1
        $this->image = $image;
125
    }
126
127
    public function getIllustration(): ?Image
128
    {
129
        return $this->illustration;
130
    }
131
132
    public function setIllustration(?Image $illustration): void
133
    {
134
        // We must trigger lazy loading, otherwise Doctrine will seriously
135
        // mess up lifecycle callbacks and delete unrelated illustration on disk
136
        if ($this->illustration) {
137
            $this->illustration->getFilename();
138
        }
139
140
        $this->illustration = $illustration;
141
    }
142
}
143