Conditions | 1 |
Paths | 1 |
Total Lines | 8 |
Code Lines | 6 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | <?php |
||
46 | public function buildRelativeUrl(AbstractFile $file) : string |
||
47 | { |
||
48 | $permalink = $this->configuration->getPostRoute(); |
||
49 | $permalink = preg_replace('/:year/', $file->getDateInFormat('Y'), $permalink); |
||
|
|||
50 | $permalink = preg_replace('/:month/', $file->getDateInFormat('m'), $permalink); |
||
51 | $permalink = preg_replace('/:day/', $file->getDateInFormat('d'), $permalink); |
||
52 | return preg_replace('/:title/', $file->getFilenameWithoutDate(), $permalink); |
||
53 | } |
||
54 | } |
||
55 |
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 sub-classes 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 parent class: