| 1 | <?php |
||
| 18 | class SmtpMailer extends AbstractMailer |
||
| 19 | { |
||
| 20 | /** |
||
| 21 | * @param string $host |
||
| 22 | * @param string $username |
||
| 23 | * @param string $password |
||
| 24 | */ |
||
| 25 | public function __construct($host, $username, $password) |
||
| 30 | |||
| 31 | /** |
||
| 32 | * @param int $port |
||
| 33 | * @return $this |
||
| 34 | */ |
||
| 35 | public function setSsl($port = 465) |
||
| 40 | |||
| 41 | /** |
||
| 42 | * @param int $port |
||
| 43 | * @return $this |
||
| 44 | */ |
||
| 45 | public function setTls($port = 587) |
||
| 50 | } |
||
| 51 |
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: