These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
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\Product\Model; |
||
15 | |||
16 | use Doctrine\Common\Collections\ArrayCollection; |
||
17 | use Doctrine\Common\Collections\Collection; |
||
18 | use Sylius\Component\Resource\Model\TimestampableTrait; |
||
19 | use Sylius\Component\Resource\Model\TranslatableTrait; |
||
20 | use Sylius\Component\Resource\Model\TranslationInterface; |
||
21 | |||
22 | class ProductVariant implements ProductVariantInterface |
||
23 | { |
||
24 | use TimestampableTrait; |
||
25 | use TranslatableTrait { |
||
26 | __construct as private initializeTranslationsCollection; |
||
27 | getTranslation as private doGetTranslation; |
||
28 | } |
||
29 | |||
30 | /** |
||
31 | * @var mixed |
||
32 | */ |
||
33 | protected $id; |
||
34 | |||
35 | /** |
||
36 | * @var string |
||
37 | */ |
||
38 | protected $code; |
||
39 | |||
40 | /** |
||
41 | * @var ProductInterface |
||
42 | */ |
||
43 | protected $product; |
||
44 | |||
45 | /** |
||
46 | * @var Collection|ProductOptionValueInterface[] |
||
47 | */ |
||
48 | protected $optionValues; |
||
49 | |||
50 | /** |
||
51 | * @var int |
||
52 | */ |
||
53 | protected $position; |
||
54 | |||
55 | public function __construct() |
||
56 | { |
||
57 | $this->initializeTranslationsCollection(); |
||
58 | $this->optionValues = new ArrayCollection(); |
||
0 ignored issues
–
show
|
|||
59 | |||
60 | $this->createdAt = new \DateTime(); |
||
61 | } |
||
62 | |||
63 | /** |
||
64 | * {@inheritdoc} |
||
65 | */ |
||
66 | public function getId() |
||
67 | { |
||
68 | return $this->id; |
||
69 | } |
||
70 | |||
71 | /** |
||
72 | * {@inheritdoc} |
||
73 | */ |
||
74 | public function getCode(): ?string |
||
75 | { |
||
76 | return $this->code; |
||
77 | } |
||
78 | |||
79 | /** |
||
80 | * {@inheritdoc} |
||
81 | */ |
||
82 | public function setCode(?string $code): void |
||
83 | { |
||
84 | $this->code = $code; |
||
85 | } |
||
86 | |||
87 | /** |
||
88 | * {@inheritdoc} |
||
89 | */ |
||
90 | public function getName(): ?string |
||
91 | { |
||
92 | return $this->getTranslation()->getName(); |
||
93 | } |
||
94 | |||
95 | /** |
||
96 | * {@inheritdoc} |
||
97 | */ |
||
98 | public function setName(?string $name): void |
||
99 | { |
||
100 | $this->getTranslation()->setName($name); |
||
101 | } |
||
102 | |||
103 | /** |
||
104 | * {@inheritdoc} |
||
105 | */ |
||
106 | public function getDescriptor(): string |
||
107 | { |
||
108 | $name = empty($this->getName()) ? $this->getProduct()->getName() : $this->getName(); |
||
109 | |||
110 | return trim(sprintf('%s (%s)', $name, $this->code)); |
||
111 | } |
||
112 | |||
113 | /** |
||
114 | * {@inheritdoc} |
||
115 | */ |
||
116 | public function getOptionValues(): Collection |
||
117 | { |
||
118 | return $this->optionValues; |
||
119 | } |
||
120 | |||
121 | /** |
||
122 | * {@inheritdoc} |
||
123 | */ |
||
124 | public function addOptionValue(ProductOptionValueInterface $optionValue): void |
||
125 | { |
||
126 | if (!$this->hasOptionValue($optionValue)) { |
||
127 | $this->optionValues->add($optionValue); |
||
128 | } |
||
129 | } |
||
130 | |||
131 | /** |
||
132 | * {@inheritdoc} |
||
133 | */ |
||
134 | public function removeOptionValue(ProductOptionValueInterface $optionValue): void |
||
135 | { |
||
136 | if ($this->hasOptionValue($optionValue)) { |
||
137 | $this->optionValues->removeElement($optionValue); |
||
138 | } |
||
139 | } |
||
140 | |||
141 | /** |
||
142 | * {@inheritdoc} |
||
143 | */ |
||
144 | public function hasOptionValue(ProductOptionValueInterface $optionValue): bool |
||
145 | { |
||
146 | return $this->optionValues->contains($optionValue); |
||
147 | } |
||
148 | |||
149 | /** |
||
150 | * {@inheritdoc} |
||
151 | */ |
||
152 | public function getProduct(): ?ProductInterface |
||
153 | { |
||
154 | return $this->product; |
||
155 | } |
||
156 | |||
157 | /** |
||
158 | * {@inheritdoc} |
||
159 | */ |
||
160 | public function setProduct(?ProductInterface $product): void |
||
161 | { |
||
162 | $this->product = $product; |
||
163 | } |
||
164 | |||
165 | /** |
||
166 | * {@inheritdoc} |
||
167 | */ |
||
168 | public function getPosition(): ?int |
||
169 | { |
||
170 | return $this->position; |
||
171 | } |
||
172 | |||
173 | /** |
||
174 | * {@inheritdoc} |
||
175 | */ |
||
176 | public function setPosition(?int $position): void |
||
177 | { |
||
178 | $this->position = $position; |
||
179 | } |
||
180 | |||
181 | /** |
||
182 | * @param string|null $locale |
||
183 | * |
||
184 | * @return ProductVariantTranslationInterface |
||
185 | */ |
||
186 | public function getTranslation(?string $locale = null): TranslationInterface |
||
187 | { |
||
188 | /** @var ProductVariantTranslationInterface $translation */ |
||
189 | $translation = $this->doGetTranslation($locale); |
||
190 | |||
191 | return $translation; |
||
192 | } |
||
193 | |||
194 | /** |
||
195 | * {@inheritdoc} |
||
196 | */ |
||
197 | protected function createTranslation(): ProductVariantTranslationInterface |
||
198 | { |
||
199 | return new ProductVariantTranslation(); |
||
200 | } |
||
201 | } |
||
202 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..