Conditions | 3 |
Paths | 6 |
Total Lines | 22 |
Code Lines | 16 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 1 | Features | 0 |
1 | <?php |
||
31 | protected function execute(InputInterface $input, OutputInterface $output) |
||
32 | { |
||
33 | $updater = new Updater(); |
||
34 | $updater->getStrategy()->setPharUrl('https://spomky-labs.github.io/jose/jose.phar'); |
||
|
|||
35 | $updater->getStrategy()->setVersionUrl('https://spomky-labs.github.io/jose/jose.phar.version'); |
||
36 | |||
37 | try { |
||
38 | $result = $updater->update(); |
||
39 | if ($result) { |
||
40 | $new = $updater->getNewVersion(); |
||
41 | $old = $updater->getOldVersion(); |
||
42 | printf( |
||
43 | 'Updated from SHA-1 %s to SHA-1 %s', $old, $new |
||
44 | ); |
||
45 | } else { |
||
46 | echo "No update needed!\n"; |
||
47 | } |
||
48 | } catch (\Exception $e) { |
||
49 | echo "Well, something happened! Either an oopsie or something involving hackers.\n"; |
||
50 | exit(1); |
||
51 | } |
||
52 | } |
||
53 | } |
||
54 |
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: