1 | <?php |
||
21 | class PhpLeadingLineReviewNoBlade extends AbstractFileReview |
||
22 | { |
||
23 | /** |
||
24 | * Determins if the given file should be revewed. |
||
25 | * |
||
26 | * @param FileInterface $file |
||
27 | * @return bool |
||
28 | */ |
||
29 | public function canReviewFile(FileInterface $file) |
||
33 | |||
34 | /** |
||
35 | * Checks if the set file starts with the correct character sequence, which |
||
36 | * helps to stop any rouge whitespace making it in before the first php tag. |
||
37 | * |
||
38 | * @link http://stackoverflow.com/a/2440685 |
||
39 | */ |
||
40 | public function review(ReporterInterface $reporter, ReviewableInterface $file) |
||
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 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: