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 | class LazyLoadingDriver implements DriverInterface |
||
18 | { |
||
19 | /** |
||
20 | * Контейнер в катором распологаются драйвера |
||
21 | * |
||
22 | * @var ContainerInterface |
||
23 | */ |
||
24 | protected $serviceLocator; |
||
25 | |||
26 | /** |
||
27 | * Идендификатор драйвера |
||
28 | * |
||
29 | * @var string |
||
30 | */ |
||
31 | protected $realDriverId; |
||
32 | |||
33 | /** |
||
34 | * LazyLoadingDriver constructor. |
||
35 | * |
||
36 | * @param ContainerInterface $container |
||
37 | * @param $realDriverId |
||
38 | */ |
||
39 | public function __construct(ContainerInterface $container, $realDriverId) |
||
44 | |||
45 | /** |
||
46 | * Возвращает контейнер в катором распологаются драйвера |
||
47 | * |
||
48 | * @return ContainerInterface |
||
49 | */ |
||
50 | public function getServiceLocator() |
||
54 | |||
55 | /** |
||
56 | * Устанавливает контейнер в катором распологаются драйвера |
||
57 | * |
||
58 | * @param ContainerInterface $serviceLocator |
||
59 | * |
||
60 | * @return $this |
||
61 | */ |
||
62 | public function setServiceLocator(ContainerInterface $serviceLocator) |
||
68 | |||
69 | /** |
||
70 | * Возвращает идендификатор драйвера |
||
71 | * |
||
72 | * @return string |
||
73 | */ |
||
74 | public function getRealDriverId() |
||
78 | |||
79 | /** |
||
80 | * Устанавливает идендификатор драйвера |
||
81 | * |
||
82 | * @param string $realDriverId |
||
83 | * |
||
84 | * @return $this |
||
85 | */ |
||
86 | public function setRealDriverId($realDriverId) |
||
92 | |||
93 | /** |
||
94 | * {@ineheritdoc} |
||
95 | * @param ReflectionClass $class |
||
96 | * |
||
97 | * @return \Metadata\ClassMetadata |
||
98 | * @throws \Nnx\JmsSerializerModule\MetadataDriver\Exception\RuntimeException |
||
99 | * @throws \Interop\Container\Exception\NotFoundException |
||
100 | * @throws \Interop\Container\Exception\ContainerException |
||
101 | */ |
||
102 | public function loadMetadataForClass(ReflectionClass $class) |
||
115 | } |
||
116 |
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.