Failed Conditions
Push — master ( 8cb271...90b6d5 )
by Sam
08:31
created

AbstractProduct::getIllustration()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 2
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Application\Model;
6
7
use Application\Traits\HasCode;
8
use Application\Traits\HasDescription;
9
use Application\Traits\HasInternalRemarks;
10
use Application\Traits\HasName;
11
use Application\Traits\HasProductType;
12
use Doctrine\ORM\Mapping as ORM;
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 HasName;
24
    use HasDescription;
25
    use HasCode;
26
    use HasInternalRemarks;
27
    use HasProductType;
28
29
    /**
30
     * @var Money
31
     *
32
     * @ORM\Column(type="CHF", options={"default" = "0.00"})
33
     */
34
    private $pricePerUnitCHF;
35
36
    /**
37
     * @var Money
38
     *
39
     * @ORM\Column(type="EUR", options={"default" = "0.00"})
40
     */
41
    private $pricePerUnitEUR;
42
43
    /**
44
     * @var bool
45
     *
46
     * @ORM\Column(type="boolean", options={"default" = 1})
47
     */
48
    private $isActive = true;
49
50
    /**
51
     * @var null|Image
52
     * @ORM\OneToOne(targetEntity="Image", orphanRemoval=true)
53
     * @ORM\JoinColumn(name="image_id", referencedColumnName="id", onDelete="CASCADE")
54
     */
55
    private $image;
56
57
    /**
58
     * @var null|Image
59
     * @ORM\OneToOne(targetEntity="Image", orphanRemoval=true)
60
     * @ORM\JoinColumn(name="illustration_id", referencedColumnName="id", onDelete="CASCADE")
61
     */
62
    private $illustration;
63
64
    /**
65
     * Constructor
66
     *
67
     * @param string $name
68
     */
69 18
    public function __construct(string $name = '')
70
    {
71 18
        $this->setName($name);
72 18
        $this->pricePerUnitCHF = Money::CHF(0);
73 18
        $this->pricePerUnitEUR = Money::EUR(0);
74 18
    }
75
76
    /**
77
     * @API\Field(type="CHF")
78
     *
79
     * @return Money
80
     */
81 9
    public function getPricePerUnitCHF(): Money
82
    {
83 9
        return $this->pricePerUnitCHF;
84
    }
85
86
    /**
87
     * @API\Input(type="CHF")
88
     *
89
     * @param Money $pricePerUnitCHF
90
     */
91 7
    public function setPricePerUnitCHF(Money $pricePerUnitCHF): void
92
    {
93 7
        $this->pricePerUnitCHF = $pricePerUnitCHF;
94 7
    }
95
96
    /**
97
     * @API\Field(type="EUR")
98
     *
99
     * @return Money
100
     */
101 1
    public function getPricePerUnitEUR(): Money
102
    {
103 1
        return $this->pricePerUnitEUR;
104
    }
105
106
    /**
107
     * @API\Input(type="EUR")
108
     *
109
     * @param Money $pricePerUnitEUR
110
     */
111 7
    public function setPricePerUnitEUR(Money $pricePerUnitEUR): void
112
    {
113 7
        $this->pricePerUnitEUR = $pricePerUnitEUR;
114 7
    }
115
116
    /**
117
     * Whether this product can be bought
118
     *
119
     * @return bool
120
     */
121
    public function isActive(): bool
122
    {
123
        return $this->isActive;
124
    }
125
126
    /**
127
     * Whether this product can be bought
128
     *
129
     * @param bool $isActive
130
     */
131
    public function setIsActive(bool $isActive): void
132
    {
133
        $this->isActive = $isActive;
134
    }
135
136
    /**
137
     * @return null|Image
138
     */
139 1
    public function getImage(): ?Image
140
    {
141 1
        return $this->image;
142
    }
143
144
    /**
145
     * @param null|Image $image
146
     */
147 1
    public function setImage(?Image $image): void
148
    {
149
        // We must trigger lazy loading, otherwise Doctrine will seriously
150
        // mess up lifecycle callbacks and delete unrelated image on disk
151 1
        if ($this->image) {
152 1
            $this->image->getFilename();
153
        }
154
155 1
        $this->image = $image;
156 1
    }
157
158
    /**
159
     * @return null|Image
160
     */
161
    public function getIllustration(): ?Image
162
    {
163
        return $this->illustration;
164
    }
165
166
    /**
167
     * @param null|Image $illustration
168
     */
169
    public function setIllustration(?Image $illustration): void
170
    {
171
        // We must trigger lazy loading, otherwise Doctrine will seriously
172
        // mess up lifecycle callbacks and delete unrelated illustration on disk
173
        if ($this->illustration) {
174
            $this->illustration->getFilename();
175
        }
176
177
        $this->illustration = $illustration;
178
    }
179
}
180