| 1 | <?php |
||
| 20 | class CoarseChecker |
||
| 21 | { |
||
| 22 | |||
| 23 | /** |
||
| 24 | * Check if file contains annotations, |
||
| 25 | * by checking if it contains @[A-Z] regular expression. |
||
| 26 | * |
||
| 27 | * It does not ensure that file really contains anniotations. |
||
| 28 | * |
||
| 29 | * @param string|Reflector|object $entity |
||
| 30 | */ |
||
| 31 | 42 | public static function mightHaveAnnotations($entity) |
|
| 63 | |||
| 64 | } |
||
| 65 |
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: