1 | <?php |
||
20 | abstract class AbstractPage extends BaseObject implements PageInterface |
||
21 | { |
||
22 | /** @var \yii\web\View */ |
||
23 | protected $view; |
||
24 | |||
25 | public $layout; |
||
26 | |||
27 | /** @var string */ |
||
28 | public $title; |
||
29 | |||
30 | /** @var null|string */ |
||
31 | protected $path; |
||
32 | |||
33 | /** @var string */ |
||
34 | protected $text; |
||
35 | |||
36 | /** @var array */ |
||
37 | protected $data = []; |
||
38 | |||
39 | /** @var string */ |
||
40 | protected $url; |
||
41 | |||
42 | /** @var null|string */ |
||
43 | protected $featuredImageUrl; |
||
44 | |||
45 | /** @var null|string */ |
||
46 | protected $slug; |
||
47 | |||
48 | /** @var null|string */ |
||
49 | protected $keywords; |
||
50 | |||
51 | /** @var null|string */ |
||
52 | protected $description; |
||
53 | |||
54 | /** @var null|string */ |
||
55 | protected $canonical; |
||
56 | |||
57 | const META_DATA = ['keywords', 'description', 'canonical']; |
||
58 | |||
59 | /** @var StorageInterface */ |
||
60 | protected $storage; |
||
61 | |||
62 | public function __construct($path = null, StorageInterface $storage = null, $config = []) |
||
76 | |||
77 | public function setData($data) |
||
89 | |||
90 | /** |
||
91 | * @return array |
||
92 | */ |
||
93 | public function getData(): array |
||
97 | |||
98 | public function getPath() |
||
102 | |||
103 | public function getDate() |
||
107 | |||
108 | public function getUrl() |
||
112 | |||
113 | public static function createFromFile($path, FileSystemStorage $storage) |
||
120 | |||
121 | public function extractData($path) |
||
135 | |||
136 | public function readFrontMatter($lines) |
||
145 | |||
146 | public function readYaml($lines) |
||
155 | |||
156 | public function readQuotedLines($lines, $headMarker, $tailMarker) |
||
174 | |||
175 | /** |
||
176 | * @param string $text |
||
177 | */ |
||
178 | public function setText(string $text): void |
||
182 | |||
183 | /** |
||
184 | * @param string $url |
||
185 | */ |
||
186 | public function setUrl(string $url): void |
||
190 | |||
191 | protected function setMetaData(): void |
||
203 | |||
204 | /** |
||
205 | * @param null|string $slug |
||
206 | */ |
||
207 | public function setSlug(?string $slug): void |
||
211 | |||
212 | /** |
||
213 | * @param null|string $keywords |
||
214 | */ |
||
215 | public function setKeywords(?string $keywords): void |
||
219 | |||
220 | /** |
||
221 | * @param null|string $description |
||
222 | */ |
||
223 | public function setDescription(?string $description): void |
||
227 | |||
228 | /** |
||
229 | * @param null|string $featuredImageUrl |
||
230 | */ |
||
231 | public function setFeaturedImageUrl(?string $featuredImageUrl): void |
||
235 | |||
236 | /** |
||
237 | * @param null|string $canonical |
||
238 | */ |
||
239 | public function setCanonical(?string $canonical): void |
||
243 | } |
||
244 |
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: