| 1 | <?php | ||
| 26 | trait InspectorTrait | ||
| 27 | { | ||
| 28 | |||
| 29 | /** | ||
| 30 | * getSession | ||
| 31 | * | ||
| 32 | * This trait should be used by Session clients. | ||
| 33 | * | ||
| 34 | * @return Session | ||
| 35 | */ | ||
| 36 | abstract protected function getSession(); | ||
| 37 | |||
| 38 | /** | ||
| 39 | * executeSql | ||
| 40 | * | ||
| 41 |      * Launch query execution expanding string {condition} with the Where query | ||
| 42 | * parameter and values. | ||
| 43 | * | ||
| 44 | * @param string $sql | ||
| 45 | * @param Where $condition | ||
| 46 | * @return ConvertedResultIterator | ||
| 47 | */ | ||
| 48 | protected function executeSql($sql, Where $condition = null) | ||
| 62 | } | ||
| 63 | 
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: