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 |
||
18 | class MarkdownFactory implements FactoryInterface |
||
|
|||
19 | { |
||
20 | |||
21 | /** |
||
22 | * Create service |
||
23 | * |
||
24 | * @param ServiceLocatorInterface $serviceLocator |
||
25 | * @return Markdown |
||
26 | */ |
||
27 | 1 | public function createService(ServiceLocatorInterface $serviceLocator) |
|
28 | { |
||
29 | 1 | if ($serviceLocator instanceof AbstractPluginManager) { |
|
30 | 1 | $serviceLocator = $serviceLocator->getServiceLocator() ?: $serviceLocator; |
|
31 | } |
||
32 | |||
33 | 1 | return $this->create($serviceLocator); |
|
34 | } |
||
35 | |||
36 | /** |
||
37 | * Create an object |
||
38 | * |
||
39 | * @param ContainerInterface $container |
||
40 | * @param string $requestedName |
||
41 | * @param null|array $options |
||
42 | * @return Markdown |
||
43 | * @throws \Interop\Container\Exception\NotFoundException |
||
44 | * @throws ServiceNotFoundException if unable to resolve the service. |
||
45 | * @throws ServiceNotCreatedException if an exception is raised when |
||
46 | * creating a service. |
||
47 | * @throws ContainerException if any other error occurs |
||
48 | */ |
||
49 | public function __invoke(ContainerInterface $container, $requestedName, array $options = null) |
||
53 | |||
54 | /** |
||
55 | * @param ServiceLocatorInterface|ContainerInterface $container |
||
56 | * @return Markdown |
||
57 | */ |
||
58 | 1 | View Code Duplication | protected function create($container) |
66 | } |
||
67 |
This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.