Conditions | 3 |
Paths | 7 |
Total Lines | 21 |
Code Lines | 16 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 1 | Features | 0 |
1 | <?php |
||
40 | protected function execute(InputInterface $input, OutputInterface $output) |
||
41 | { |
||
42 | $updater = new Updater(); |
||
43 | $updater->setStrategy(Updater::STRATEGY_GITHUB); |
||
44 | $updater->getStrategy()->setPackageName('spomky-labs/jose'); |
||
|
|||
45 | $updater->getStrategy()->setPharName('jose'); |
||
46 | $updater->getStrategy()->setCurrentLocalVersion('7.0.0'); |
||
47 | |||
48 | try { |
||
49 | $result = $updater->update(); |
||
50 | if ($result) { |
||
51 | $new = $updater->getNewVersion(); |
||
52 | $old = $updater->getOldVersion(); |
||
53 | $output->write(sprintf('Updated from %s to %s', $old, $new)); |
||
54 | } else { |
||
55 | $output->write('Already up-to-date.'); |
||
56 | } |
||
57 | } catch (\Exception $e) { |
||
58 | $output->write('Something went wrong during the update.'); |
||
59 | } |
||
60 | } |
||
61 | } |
||
62 |
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: