1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* This file was created by the developers from BitBag. |
5
|
|
|
* Feel free to contact us once you face any issues or want to start |
6
|
|
|
* another great project. |
7
|
|
|
* You can find more information about us on https://bitbag.shop and write us |
8
|
|
|
* an email on [email protected]. |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
declare(strict_types=1); |
12
|
|
|
|
13
|
|
|
namespace BitBag\CmsPlugin\Entity; |
14
|
|
|
|
15
|
|
|
use Sylius\Component\Resource\Model\ToggleableTrait; |
16
|
|
|
use Sylius\Component\Resource\Model\TranslatableTrait; |
17
|
|
|
use Sylius\Component\Resource\Model\TranslationInterface; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @author Mikołaj Król <[email protected]> |
21
|
|
|
*/ |
22
|
|
|
class FrequentlyAskedQuestion implements FrequentlyAskedQuestionInterface |
23
|
|
|
{ |
24
|
|
|
use SectionAssociationTrait; |
25
|
|
|
use ToggleableTrait, |
26
|
|
|
TranslatableTrait { |
27
|
|
|
__construct as private initializeTranslationsCollection; |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @var int |
32
|
|
|
*/ |
33
|
|
|
protected $id; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @var null|string |
37
|
|
|
*/ |
38
|
|
|
protected $code; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @var null|int |
42
|
|
|
*/ |
43
|
|
|
protected $position; |
44
|
|
|
|
45
|
|
|
public function __construct() |
46
|
|
|
{ |
47
|
|
|
$this->initializeSectionsCollection(); |
48
|
|
|
$this->initializeTranslationsCollection(); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* {@inheritdoc} |
53
|
|
|
*/ |
54
|
|
|
public function getId(): int |
55
|
|
|
{ |
56
|
|
|
return $this->id; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* {@inheritdoc} |
61
|
|
|
*/ |
62
|
|
|
public function getCode(): ?string |
63
|
|
|
{ |
64
|
|
|
return $this->code; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* {@inheritdoc} |
69
|
|
|
*/ |
70
|
|
|
public function setCode(?string $code): void |
71
|
|
|
{ |
72
|
|
|
$this->code = $code; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* {@inheritdoc} |
77
|
|
|
*/ |
78
|
|
|
public function getPosition(): ?int |
79
|
|
|
{ |
80
|
|
|
return $this->position; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* {@inheritdoc} |
85
|
|
|
*/ |
86
|
|
|
public function setPosition(?int $position): void |
87
|
|
|
{ |
88
|
|
|
$this->position = $position; |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* {@inheritdoc} |
93
|
|
|
*/ |
94
|
|
|
public function getQuestion(): ?string |
95
|
|
|
{ |
96
|
|
|
return $this->getFrequentlyAskedQuestionTranslation()->getQuestion(); |
|
|
|
|
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* {@inheritdoc} |
101
|
|
|
*/ |
102
|
|
|
public function setQuestion(?string $question): void |
103
|
|
|
{ |
104
|
|
|
$this->getFrequentlyAskedQuestionTranslation()->setQuestion($question); |
|
|
|
|
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* {@inheritdoc} |
109
|
|
|
*/ |
110
|
|
|
public function getAnswer(): ?string |
111
|
|
|
{ |
112
|
|
|
return $this->getFrequentlyAskedQuestionTranslation()->getAnswer(); |
|
|
|
|
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* {@inheritdoc} |
117
|
|
|
*/ |
118
|
|
|
public function setAnswer(?string $answer): void |
119
|
|
|
{ |
120
|
|
|
$this->getFrequentlyAskedQuestionTranslation()->setAnswer($answer); |
|
|
|
|
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
/** |
124
|
|
|
* @return TranslationInterface|FrequentlyAskedQuestionTranslationInterface |
125
|
|
|
*/ |
126
|
|
|
protected function getFrequentlyAskedQuestionTranslation(): TranslationInterface |
127
|
|
|
{ |
128
|
|
|
return $this->getTranslation(); |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
/** |
132
|
|
|
* {@inheritdoc} |
133
|
|
|
*/ |
134
|
|
|
protected function createTranslation(): TranslationInterface |
135
|
|
|
{ |
136
|
|
|
return new FrequentlyAskedQuestionTranslation(); |
137
|
|
|
} |
138
|
|
|
} |
139
|
|
|
|
Let’s take a look at an example:
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.
Available Fixes
Change the type-hint for the parameter:
Add an additional type-check:
Add the method to the interface: