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 |
||
17 | View Code Duplication | class ErusevParsedownAdapterFactory implements FactoryInterface |
|
18 | { |
||
19 | |||
20 | /** |
||
21 | * Create service |
||
22 | * |
||
23 | * @param ServiceLocatorInterface $serviceLocator |
||
24 | * @return mixed |
||
25 | */ |
||
26 | 1 | public function createService(ServiceLocatorInterface $serviceLocator) |
|
30 | |||
31 | /** |
||
32 | * Create an object |
||
33 | * |
||
34 | * @param ContainerInterface $container |
||
35 | * @param string $requestedName |
||
36 | * @param null|array $options |
||
37 | * @return ErusevParsedownAdapter |
||
38 | * @throws \Interop\Container\Exception\NotFoundException |
||
39 | * @throws ServiceNotFoundException if unable to resolve the service. |
||
40 | * @throws ServiceNotCreatedException if an exception is raised when |
||
41 | * creating a service. |
||
42 | * @throws ContainerException if any other error occurs |
||
43 | */ |
||
44 | public function __invoke(ContainerInterface $container, $requestedName, array $options = null) |
||
48 | |||
49 | |||
50 | /** |
||
51 | * @param ServiceLocatorInterface|ContainerInterface $container |
||
52 | * @return ErusevParsedownAdapter |
||
53 | */ |
||
54 | 1 | protected function create($container) |
|
64 | } |
||
65 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.