AbstractProduct::setPricePerUnitEUR()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

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