| Conditions | 1 |
| Paths | 1 |
| Total Lines | 14 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 3 |
| CRAP Score | 1.343 |
| Changes | 0 | ||
| 1 | <?php |
||
| 21 | 5 | public function register() |
|
| 22 | { |
||
| 23 | $this->getContainer()->share(Event::class, function () { |
||
|
|
|||
| 24 | 5 | $app = $this->getContainer()->get(Application::class); |
|
| 25 | 5 | return new Event($app); |
|
| 26 | }); |
||
| 27 | |||
| 28 | $this->getContainer()->share(Service::class, function () { |
||
| 29 | $config = $this->getContainer()->get(Config::class); |
||
| 30 | $app = $this->getContainer()->get(Application::class); |
||
| 31 | $cache = $this->getContainer()->get(Cache::class); |
||
| 32 | return new Service($config['service'], $app, $cache); |
||
| 33 | }); |
||
| 34 | } |
||
| 35 | } |
||
| 36 |
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: