1 | <?php |
||
21 | class Page implements PageInterface |
||
22 | { |
||
23 | use ToggleableTrait; |
||
24 | use ProductsAwareTrait; |
||
25 | use SectionableTrait; |
||
26 | use TimestampableTrait; |
||
27 | use ChannelsAwareTrait; |
||
28 | use TranslatableTrait { |
||
29 | __construct as protected initializeTranslationsCollection; |
||
30 | } |
||
31 | |||
32 | /** @var int */ |
||
33 | protected $id; |
||
34 | |||
35 | /** @var string */ |
||
36 | protected $code; |
||
37 | |||
38 | public function __construct() |
||
48 | |||
49 | public function getId(): ?int |
||
53 | |||
54 | public function setId(?int $id): void |
||
58 | |||
59 | public function getCode(): ?string |
||
63 | |||
64 | public function setCode(?string $code): void |
||
68 | |||
69 | public function getSlug(): ?string |
||
73 | |||
74 | public function setSlug(?string $slug): void |
||
78 | |||
79 | public function getMetaKeywords(): ?string |
||
83 | |||
84 | public function setMetaKeywords(?string $metaKeywords): void |
||
88 | |||
89 | public function getMetaDescription(): ?string |
||
93 | |||
94 | public function setMetaDescription(?string $metaDescription): void |
||
98 | |||
99 | public function getContent(): ?string |
||
103 | |||
104 | public function setContent(?string $content): void |
||
108 | |||
109 | public function getName(): ?string |
||
113 | |||
114 | public function setName(?string $name): void |
||
118 | |||
119 | public function getNameWhenLinked(): ?string |
||
123 | |||
124 | public function setNameWhenLinked(?string $nameWhenLinked): void |
||
128 | |||
129 | public function getDescriptionWhenLinked(): ?string |
||
133 | |||
134 | public function setDescriptionWhenLinked(?string $descriptionWhenLinked): void |
||
138 | |||
139 | public function getBreadcrumb(): ?string |
||
143 | |||
144 | public function setBreadcrumb(?string $breadcrumb): void |
||
148 | |||
149 | public function getImage(): ?ImageInterface |
||
153 | |||
154 | public function setImage(?ImageInterface $image): void |
||
158 | |||
159 | public function getTitle(): ?string |
||
163 | |||
164 | public function setTitle(?string $title): void |
||
168 | |||
169 | /** |
||
170 | * @return PageTranslationInterface|TranslationInterface|null |
||
171 | */ |
||
172 | protected function getPageTranslation(): PageTranslationInterface |
||
176 | |||
177 | protected function createTranslation(): ?PageTranslationInterface |
||
181 | } |
||
182 |
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: