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 | abstract class AbstractAdapterFactory |
||
| 16 | { |
||
| 17 | /** |
||
| 18 | * @var array |
||
| 19 | */ |
||
| 20 | protected $options; |
||
| 21 | |||
| 22 | /** |
||
| 23 | * AbstractAdapterFactory constructor. |
||
| 24 | * |
||
| 25 | * @param array $options |
||
| 26 | */ |
||
| 27 | 45 | public function __construct(array $options = []) |
|
| 31 | |||
| 32 | /** |
||
| 33 | * Set creation options. |
||
| 34 | */ |
||
| 35 | 45 | public function setCreationOptions(array $options) |
|
| 39 | |||
| 40 | public function __invoke(ContainerInterface $container, $requestedName, array $options = null): AdapterInterface |
||
| 54 | |||
| 55 | View Code Duplication | public function createService(ContainerInterface $container): AdapterInterface |
|
| 63 | |||
| 64 | /** |
||
| 65 | * Merges the options given from the ServiceLocator Config object with the create options of the class. |
||
| 66 | */ |
||
| 67 | protected function mergeMvcConfig(ContainerInterface $container, string $requestedName = null) |
||
| 82 | |||
| 83 | /** |
||
| 84 | * @throws InvalidArgumentException |
||
| 85 | */ |
||
| 86 | public function getLazyFactory(ContainerInterface $container): LazyLoadingValueHolderFactory |
||
| 119 | |||
| 120 | /** |
||
| 121 | * Create service. |
||
| 122 | */ |
||
| 123 | abstract protected function doCreateService(ContainerInterface $container): AdapterInterface; |
||
| 124 | |||
| 125 | /** |
||
| 126 | * Implement in adapter. |
||
| 127 | * |
||
| 128 | * @throw UnexpectedValueException |
||
| 129 | */ |
||
| 130 | abstract protected function validateConfig(); |
||
| 131 | } |
||
| 132 |