Completed
Push — master ( 8e33ff...1a8186 )
by Kamil
18:07
created

Attribute::getTranslation()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 1
1
<?php
2
3
/*
4
 * This file is part of the Sylius package.
5
 *
6
 * (c) Paweł Jędrzejewski
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
declare(strict_types=1);
13
14
namespace Sylius\Component\Attribute\Model;
15
16
use Sylius\Component\Attribute\AttributeType\TextAttributeType;
17
use Sylius\Component\Resource\Model\TimestampableTrait;
18
use Sylius\Component\Resource\Model\TranslatableTrait;
19
use Sylius\Component\Resource\Model\TranslationInterface;
20
21
class Attribute implements AttributeInterface
22
{
23
    use TimestampableTrait;
24
    use TranslatableTrait {
25
        __construct as private initializeTranslationsCollection;
26
        getTranslation as private doGetTranslation;
27
    }
28
29
    /**
30
     * @var mixed
31
     */
32
    protected $id;
33
34
    /**
35
     * @var string
36
     */
37
    protected $code;
38
39
    /**
40
     * @var string
41
     */
42
    protected $type = TextAttributeType::TYPE;
43
44
    /**
45
     * @var array
46
     */
47
    protected $configuration = [];
48
49
    /**
50
     * @var string
51
     */
52
    protected $storageType;
53
54
    /**
55
     * @var int
56
     */
57
    protected $position;
58
59
    public function __construct()
60
    {
61
        $this->initializeTranslationsCollection();
62
63
        $this->createdAt = new \DateTime();
64
    }
65
66
    /**
67
     * {@inheritdoc}
68
     */
69
    public function __toString(): string
70
    {
71
        return (string) $this->getName();
72
    }
73
74
    /**
75
     * {@inheritdoc}
76
     */
77
    public function getId()
78
    {
79
        return $this->id;
80
    }
81
82
    /**
83
     * {@inheritdoc}
84
     */
85
    public function getCode(): ?string
86
    {
87
        return $this->code;
88
    }
89
90
    /**
91
     * {@inheritdoc}
92
     */
93
    public function setCode(?string $code): void
94
    {
95
        $this->code = $code;
96
    }
97
98
    /**
99
     * {@inheritdoc}
100
     */
101
    public function getName(): ?string
102
    {
103
        return $this->getTranslation()->getName();
104
    }
105
106
    /**
107
     * {@inheritdoc}
108
     */
109
    public function setName(?string $name): void
110
    {
111
        $this->getTranslation()->setName($name);
112
    }
113
114
    /**
115
     * {@inheritdoc}
116
     */
117
    public function getType(): ?string
118
    {
119
        return $this->type;
120
    }
121
122
    /**
123
     * {@inheritdoc}
124
     */
125
    public function setType(?string $type): void
126
    {
127
        $this->type = $type;
128
    }
129
130
    /**
131
     * {@inheritdoc}
132
     */
133
    public function getConfiguration(): array
134
    {
135
        return $this->configuration;
136
    }
137
138
    /**
139
     * {@inheritdoc}
140
     */
141
    public function setConfiguration(array $configuration): void
142
    {
143
        $this->configuration = $configuration;
144
    }
145
146
    /**
147
     * {@inheritdoc}
148
     */
149
    public function getStorageType(): ?string
150
    {
151
        return $this->storageType;
152
    }
153
154
    /**
155
     * {@inheritdoc}
156
     */
157
    public function setStorageType(?string $storageType): void
158
    {
159
        $this->storageType = $storageType;
160
    }
161
162
    /**
163
     * {@inheritdoc}
164
     */
165
    public function getPosition(): ?int
166
    {
167
        return $this->position;
168
    }
169
170
    /**
171
     * {@inheritdoc}
172
     */
173
    public function setPosition(?int $position): void
174
    {
175
        $this->position = $position;
176
    }
177
178
    /**
179
     * @param string|null $locale
180
     *
181
     * @return AttributeTranslationInterface
182
     */
183
    public function getTranslation(?string $locale = null): TranslationInterface
184
    {
185
        /** @var AttributeTranslationInterface $translation */
186
        $translation = $this->doGetTranslation($locale);
187
188
        return $translation;
189
    }
190
191
    /**
192
     * @return AttributeTranslationInterface
193
     */
194
    protected function createTranslation(): AttributeTranslationInterface
195
    {
196
        return new AttributeTranslation();
197
    }
198
}
199