1 | <?php |
||
12 | class SyntaxRule implements Rule |
||
13 | { |
||
14 | private $jsHintExecutable; |
||
15 | private $tmpDir; |
||
16 | |||
17 | /** |
||
18 | * @param $jsHintExecutable string The path to the jshint executable |
||
19 | * @param $tmpDir string The directory the temporary js file should be stored |
||
20 | */ |
||
21 | public function init($jsHintExecutable = '', $tmpDir = '/tmp') |
||
26 | |||
27 | public function validate(ResponseInterface $response) |
||
47 | } |
||
48 |
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: