Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
| 1 | <?php |
||
| 10 | class LazyEventSubscriberServiceProvider implements ServiceProviderInterface |
||
| 11 | { |
||
| 12 | /** |
||
| 13 | * @var LazyServiceFactory |
||
| 14 | */ |
||
| 15 | protected $lazyServiceFactory; |
||
| 16 | |||
| 17 | /** |
||
| 18 | * @var string |
||
| 19 | */ |
||
| 20 | protected $eventDispatcherServiceName; |
||
| 21 | |||
| 22 | /** |
||
| 23 | * @var string[] |
||
| 24 | */ |
||
| 25 | protected $eventSubscriberServiceNames; |
||
| 26 | |||
| 27 | /** |
||
| 28 | * @param LazyServiceFactory $lazyServiceFactory |
||
| 29 | * @param string $eventDispatcherServiceName |
||
| 30 | * @param string[] $eventSubscriberServiceNames |
||
| 31 | */ |
||
| 32 | 4 | public function __construct( |
|
| 41 | |||
| 42 | /** |
||
| 43 | * {@inheritdoc} |
||
| 44 | */ |
||
| 45 | 4 | public function register(Container $container): void |
|
| 63 | |||
| 64 | /** |
||
| 65 | * @param Container $container |
||
| 66 | * |
||
| 67 | * @throws \InvalidArgumentException When container cannot instantiate EventDispatcher object |
||
| 68 | * |
||
| 69 | * @return EventDispatcherInterface |
||
| 70 | */ |
||
| 71 | 4 | protected function getEventDispatcher(Container $container): EventDispatcherInterface |
|
| 85 | } |
||
| 86 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: