Completed
Push — master ( 224468...971710 )
by
unknown
08:12 queued 10s
created

Vendor::getName()   A

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
declare(strict_types=1);
4
5
namespace Odiseo\SyliusVendorPlugin\Entity;
6
7
use Doctrine\Common\Collections\ArrayCollection;
8
use Doctrine\Common\Collections\Collection;
9
use Sylius\Component\Channel\Model\ChannelInterface;
10
use Sylius\Component\Product\Model\ProductInterface;
11
use Sylius\Component\Resource\Model\TimestampableTrait;
12
use Sylius\Component\Resource\Model\ToggleableTrait;
13
use Sylius\Component\Resource\Model\TranslatableTrait;
14
use Sylius\Component\Resource\Model\TranslationInterface;
15
use Symfony\Component\HttpFoundation\File\File;
16
17
class Vendor implements VendorInterface
18
{
19
    use TranslatableTrait {
20
        __construct as private initializeTranslationsCollection;
21
        getTranslation as private doGetTranslation;
22
    }
23
    use TimestampableTrait;
24
    use ToggleableTrait;
25
26
    /** @var int|null */
27
    private $id;
28
29
    /** @var string */
30
    private $name;
31
32
    /** @var string|null */
33
    private $slug;
34
35
    /** @var string */
36
    private $email;
37
38
    /** @var File */
39
    private $logoFile;
40
41
    /** @var string */
42
    private $logoName;
43
44
    /** @var ArrayCollection|ChannelInterface[] */
45
    private $channels;
46
47
    /** @var ArrayCollection|ProductInterface[] */
48
    private $products;
49
50
    public function __construct()
51
    {
52
        $this->initializeTranslationsCollection();
53
54
        $this->channels = new ArrayCollection();
55
        $this->products = new ArrayCollection();
56
        $this->createdAt = new \DateTime();
57
    }
58
59
    /**
60
     * {@inheritdoc}
61
     */
62
    public function getId(): ?int
63
    {
64
        return $this->id;
65
    }
66
67
    /**
68
     * {@inheritdoc}
69
     */
70
    public function getName(): string
71
    {
72
        return $this->name;
73
    }
74
75
    /**
76
     * {@inheritdoc}
77
     */
78
    public function setName(string $name): void
79
    {
80
        $this->name = $name;
81
    }
82
83
    /**
84
     * {@inheritdoc}
85
     */
86
    public function getDescription(): string
87
    {
88
        /** @var VendorTranslationInterface $vendorTranslation */
89
        $vendorTranslation = $this->getTranslation();
90
91
        return $vendorTranslation->getDescription();
92
    }
93
94
    /**
95
     * {@inheritdoc}
96
     */
97
    public function setDescription(string $description): void
98
    {
99
        /** @var VendorTranslationInterface $vendorTranslation */
100
        $vendorTranslation = $this->getTranslation();
101
102
        $vendorTranslation->setDescription($description);
103
    }
104
105
    /**
106
     * {@inheritdoc}
107
     */
108
    public function getSlug(): ?string
109
    {
110
        return $this->slug;
111
    }
112
113
    /**
114
     * {@inheritdoc}
115
     */
116
    public function setSlug(?string $slug = null): void
117
    {
118
        $this->slug = $slug;
119
    }
120
121
    /**
122
     * {@inheritdoc}
123
     */
124
    public function getEmail(): string
125
    {
126
        return $this->email;
127
    }
128
129
    /**
130
     * {@inheritdoc}
131
     */
132
    public function setEmail(string $email): void
133
    {
134
        $this->email = $email;
135
    }
136
137
    /**
138
     * {@inheritdoc}
139
     */
140
    public function getChannels(): Collection
141
    {
142
        return $this->channels;
143
    }
144
145
    /**
146
     * {@inheritdoc}
147
     */
148
    public function hasChannel(ChannelInterface $channel): bool
149
    {
150
        return $this->channels->contains($channel);
151
    }
152
153
    /**
154
     * {@inheritdoc}
155
     */
156
    public function addChannel(ChannelInterface $channel): void
157
    {
158
        if (!$this->hasChannel($channel)) {
159
            $this->channels->add($channel);
160
161
            if ($channel instanceof VendorsAwareInterface) {
162
                $channel->addVendor($this);
163
            }
164
        }
165
    }
166
167
    /**
168
     * {@inheritdoc}
169
     */
170
    public function removeChannel(ChannelInterface $channel): void
171
    {
172
        if ($this->hasChannel($channel)) {
173
            $this->channels->removeElement($channel);
174
175
            if ($channel instanceof VendorsAwareInterface) {
176
                $channel->removeVendor($this);
177
            }
178
        }
179
    }
180
181
    /**
182
     * {@inheritdoc}
183
     */
184
    public function getProducts(): Collection
185
    {
186
        return $this->products;
187
    }
188
189
    /**
190
     * {@inheritdoc}
191
     */
192
    public function hasProduct(ProductInterface $product): bool
193
    {
194
        return $this->products->contains($product);
195
    }
196
197
    /**
198
     * {@inheritdoc}
199
     */
200
    public function addProduct(ProductInterface $product): void
201
    {
202
        if (!$this->hasProduct($product)) {
203
            $this->products->add($product);
204
205
            if ($product instanceof VendorAwareInterface) {
206
                $product->setVendor($this);
207
            }
208
        }
209
    }
210
211
    /**
212
     * {@inheritdoc}
213
     */
214
    public function removeProduct(ProductInterface $product): void
215
    {
216
        if ($this->hasProduct($product)) {
217
            $this->products->removeElement($product);
218
219
            if ($product instanceof VendorAwareInterface) {
220
                $product->setVendor(null);
221
            }
222
        }
223
    }
224
225
    /**
226
     * {@inheritdoc}
227
     */
228
    public function setLogoFile(File $file): void
229
    {
230
        $this->logoFile = $file;
231
232
        $this->setUpdatedAt(new \DateTime());
233
    }
234
235
    /**
236
     * {@inheritdoc}
237
     */
238
    public function getLogoFile(): ?File
239
    {
240
        return $this->logoFile;
241
    }
242
243
    /**
244
     * {@inheritdoc}
245
     */
246
    public function setLogoName(string $logoName): void
247
    {
248
        $this->logoName = $logoName;
249
    }
250
251
    /**
252
     * {@inheritdoc}
253
     */
254
    public function getLogoName(): string
255
    {
256
        return $this->logoName;
257
    }
258
259
    /**
260
     * {@inheritdoc}
261
     */
262
    protected function createTranslation(): TranslationInterface
263
    {
264
        return new VendorTranslation();
265
    }
266
}
267