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 ProductOption implements ProductOptionInterface |
||
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 int |
||
42 | */ |
||
43 | protected $position; |
||
44 | |||
45 | /** |
||
46 | * @var Collection|ProductOptionValueInterface[] |
||
47 | */ |
||
48 | protected $values; |
||
49 | |||
50 | public function __construct() |
||
51 | { |
||
52 | $this->initializeTranslationsCollection(); |
||
53 | |||
54 | $this->values = new ArrayCollection(); |
||
0 ignored issues
–
show
|
|||
55 | $this->createdAt = new \DateTime(); |
||
56 | } |
||
57 | |||
58 | /** |
||
59 | * @return string |
||
60 | */ |
||
61 | public function __toString(): string |
||
62 | { |
||
63 | return (string) $this->getName(); |
||
64 | } |
||
65 | |||
66 | /** |
||
67 | * {@inheritdoc} |
||
68 | */ |
||
69 | public function getId() |
||
70 | { |
||
71 | return $this->id; |
||
72 | } |
||
73 | |||
74 | /** |
||
75 | * {@inheritdoc} |
||
76 | */ |
||
77 | public function getCode(): ?string |
||
78 | { |
||
79 | return $this->code; |
||
80 | } |
||
81 | |||
82 | /** |
||
83 | * {@inheritdoc} |
||
84 | */ |
||
85 | public function setCode(?string $code): void |
||
86 | { |
||
87 | $this->code = $code; |
||
88 | } |
||
89 | |||
90 | /** |
||
91 | * {@inheritdoc} |
||
92 | */ |
||
93 | public function getName(): ?string |
||
94 | { |
||
95 | return $this->getTranslation()->getName(); |
||
96 | } |
||
97 | |||
98 | /** |
||
99 | * {@inheritdoc} |
||
100 | */ |
||
101 | public function setName(?string $name): void |
||
102 | { |
||
103 | $this->getTranslation()->setName($name); |
||
104 | } |
||
105 | |||
106 | /** |
||
107 | * {@inheritdoc} |
||
108 | */ |
||
109 | public function getPosition(): ?int |
||
110 | { |
||
111 | return $this->position; |
||
112 | } |
||
113 | |||
114 | /** |
||
115 | * {@inheritdoc} |
||
116 | */ |
||
117 | public function setPosition(?int $position): void |
||
118 | { |
||
119 | $this->position = $position; |
||
120 | } |
||
121 | |||
122 | /** |
||
123 | * {@inheritdoc} |
||
124 | */ |
||
125 | public function getValues(): Collection |
||
126 | { |
||
127 | return $this->values; |
||
128 | } |
||
129 | |||
130 | /** |
||
131 | * {@inheritdoc} |
||
132 | */ |
||
133 | public function addValue(ProductOptionValueInterface $value): void |
||
134 | { |
||
135 | if (!$this->hasValue($value)) { |
||
136 | $value->setOption($this); |
||
137 | $this->values->add($value); |
||
138 | } |
||
139 | } |
||
140 | |||
141 | /** |
||
142 | * {@inheritdoc} |
||
143 | */ |
||
144 | public function removeValue(ProductOptionValueInterface $value): void |
||
145 | { |
||
146 | if ($this->hasValue($value)) { |
||
147 | $this->values->removeElement($value); |
||
148 | $value->setOption(null); |
||
149 | } |
||
150 | } |
||
151 | |||
152 | /** |
||
153 | * {@inheritdoc} |
||
154 | */ |
||
155 | public function hasValue(ProductOptionValueInterface $value): bool |
||
156 | { |
||
157 | return $this->values->contains($value); |
||
158 | } |
||
159 | |||
160 | /** |
||
161 | * @param string|null $locale |
||
162 | * |
||
163 | * @return ProductOptionTranslationInterface |
||
164 | */ |
||
165 | public function getTranslation(?string $locale = null): TranslationInterface |
||
166 | { |
||
167 | /** @var ProductOptionTranslationInterface $translation */ |
||
168 | $translation = $this->doGetTranslation($locale); |
||
169 | |||
170 | return $translation; |
||
171 | } |
||
172 | |||
173 | /** |
||
174 | * {@inheritdoc} |
||
175 | */ |
||
176 | protected function createTranslation(): ProductOptionTranslationInterface |
||
177 | { |
||
178 | return new ProductOptionTranslation(); |
||
179 | } |
||
180 | } |
||
181 |
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..