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 |
||
| 15 | Container, ServiceProviderInterface |
||
| 16 | }; |
||
| 17 | use Psr\Cache\CacheItemPoolInterface as PsrCacheItemPoolInterface; |
||
| 18 | |||
| 19 | /** |
||
| 20 | * Cache service provider |
||
| 21 | */ |
||
| 22 | class CacheServiceProvider implements ServiceProviderInterface |
||
| 23 | { |
||
| 24 | /** |
||
| 25 | * Registers the service provider with a DI container. |
||
| 26 | * |
||
| 27 | * @param Container $container The DI container. |
||
| 28 | * |
||
| 29 | * @return void |
||
| 30 | */ |
||
| 31 | 1 | public function register(Container $container) |
|
| 38 | |||
| 39 | /** |
||
| 40 | * Get the `cache` service |
||
| 41 | * |
||
| 42 | * @param Container $container The DI container. |
||
| 43 | * |
||
| 44 | * @return PsrCacheItemPoolInterface |
||
| 45 | * |
||
| 46 | * @throws \InvalidArgumentException |
||
| 47 | */ |
||
| 48 | 6 | public function getCacheService(Container $container) : PsrCacheItemPoolInterface |
|
| 93 | } |
||
| 94 |