| 1 | <?php |
||
| 18 | final class PostRoute implements RouteInterface |
||
| 19 | { |
||
| 20 | /** |
||
| 21 | * @var Configuration |
||
| 22 | */ |
||
| 23 | private $configuration; |
||
| 24 | |||
| 25 | public function __construct(Configuration $configuration) |
||
| 29 | |||
| 30 | public function matches(AbstractFile $file) : bool |
||
| 34 | |||
| 35 | /** |
||
| 36 | * @param PostFile $file |
||
| 37 | */ |
||
| 38 | public function buildOutputPath(AbstractFile $file) : string |
||
| 42 | |||
| 43 | /** |
||
| 44 | * @param PostFile $file |
||
| 45 | */ |
||
| 46 | public function buildRelativeUrl(AbstractFile $file) : string |
||
| 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: