Conditions | 3 |
Paths | 7 |
Total Lines | 21 |
Code Lines | 16 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | <?php |
||
34 | protected function execute(InputInterface $input, OutputInterface $output) |
||
35 | { |
||
36 | $updater = new Updater(); |
||
37 | $updater->setStrategy(Updater::STRATEGY_GITHUB); |
||
38 | $updater->getStrategy()->setPackageName('spomky-labs/jose'); |
||
|
|||
39 | $updater->getStrategy()->setPharName('jose'); |
||
40 | $updater->getStrategy()->setCurrentLocalVersion('7.0.0'); |
||
41 | |||
42 | try { |
||
43 | $result = $updater->update(); |
||
44 | if ($result) { |
||
45 | $new = $updater->getNewVersion(); |
||
46 | $old = $updater->getOldVersion(); |
||
47 | $output->write(sprintf('Updated from SHA-1 %s to SHA-1 %s', $old, $new)); |
||
48 | } else { |
||
49 | $output->write('No update needed!'); |
||
50 | } |
||
51 | } catch (\Exception $e) { |
||
52 | $output->write('Well, something happened! Either an oopsie or something involving hackers.'); |
||
53 | } |
||
54 | } |
||
55 | } |
||
56 |
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: