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