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 |
||
| 20 | class PagerProviderRegistry implements ContainerAwareInterface |
||
| 21 | { |
||
| 22 | use ContainerAwareTrait; |
||
| 23 | |||
| 24 | /** @var array */ |
||
| 25 | private $providers = []; |
||
| 26 | |||
| 27 | /** |
||
| 28 | * @param array $providers |
||
| 29 | */ |
||
| 30 | 4 | public function __construct(array $providers) |
|
| 34 | |||
| 35 | /** |
||
| 36 | * Gets all registered providers. |
||
| 37 | * |
||
| 38 | * Providers will be indexed by "index/type" strings in the returned array. |
||
| 39 | * |
||
| 40 | * @return PagerProviderInterface[] |
||
| 41 | */ |
||
| 42 | public function getAllProviders() |
||
| 54 | |||
| 55 | /** |
||
| 56 | * Gets all providers for an index. |
||
| 57 | * |
||
| 58 | * Providers will be indexed by "type" strings in the returned array. |
||
| 59 | * |
||
| 60 | * @param string $index |
||
| 61 | * |
||
| 62 | * @return PagerProviderInterface[]| |
||
| 63 | * |
||
| 64 | * @throws \InvalidArgumentException if no providers were registered for the index |
||
| 65 | */ |
||
| 66 | public function getIndexProviders($index) |
||
| 79 | |||
| 80 | /** |
||
| 81 | * Gets the provider for an index and type. |
||
| 82 | * |
||
| 83 | * @param string $index |
||
| 84 | * @param string $type |
||
| 85 | * |
||
| 86 | * @return PagerProviderInterface |
||
| 87 | * |
||
| 88 | * @throws \InvalidArgumentException if no provider was registered for the index and type |
||
| 89 | */ |
||
| 90 | View Code Duplication | public function getProvider($index, $type) |
|
| 98 | } |
||
| 99 |