| Conditions | 5 |
| Paths | 6 |
| Total Lines | 23 |
| Code Lines | 12 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 1 |
| 1 | <?php |
||
| 22 | public function register(Container $application) |
||
| 23 | { |
||
| 24 | $basePath = $application->get('path'); |
||
| 25 | |||
| 26 | $configuration = new Configuration(array( |
||
| 27 | "$basePath/config/config.default.php", |
||
| 28 | "$basePath/config/config.php" |
||
| 29 | )); |
||
| 30 | |||
| 31 | $application->register(array( |
||
| 32 | 'Darya\Foundation\Configuration' => $configuration |
||
| 33 | )); |
||
| 34 | |||
| 35 | foreach ($configuration['aliases'] as $alias => $service) { |
||
| 36 | $application->alias($alias, $service); |
||
| 37 | } |
||
| 38 | |||
| 39 | foreach ($configuration['services'] as $service) { |
||
| 40 | if (class_exists($service) && is_subclass_of($service, 'Darya\Service\Contracts\Provider')) { |
||
| 41 | $application->provide($application->create($service)); |
||
|
|
|||
| 42 | } |
||
| 43 | } |
||
| 44 | } |
||
| 45 | } |
||
| 46 |
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: