| Conditions | 1 |
| Paths | 1 |
| Total Lines | 17 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 11 |
| CRAP Score | 1 |
| Changes | 0 | ||
| 1 | <?php |
||
| 17 | 3 | public function register() |
|
| 18 | { |
||
| 19 | $this->getContainer()->share(Clickhouse::class, function () { |
||
|
|
|||
| 20 | 2 | return new Clickhouse($this->getContainer()); |
|
| 21 | 3 | }); |
|
| 22 | |||
| 23 | $this->getContainer()->share(Client::class, function () { |
||
| 24 | 3 | $serviceName = $this->getContainer()->get(Service::class)->getName(); |
|
| 25 | 3 | $config = $this->getContainer()->get(Config::class)['clickhouse']; |
|
| 26 | |||
| 27 | 3 | $clickhouse = new Client($config); |
|
| 28 | 3 | $clickhouse->write('create database if not exists '.$serviceName); |
|
| 29 | 3 | $clickhouse->database($serviceName); |
|
| 30 | |||
| 31 | 3 | return $clickhouse; |
|
| 32 | 3 | }); |
|
| 33 | 3 | } |
|
| 34 | } |
||
| 35 |
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: