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 |
||
37 | View Code Duplication | class CategoryCsvSerializerFactory implements SerializerFactoryInterface |
|
|
|||
38 | { |
||
39 | |||
40 | /** |
||
41 | * The DI container instance. |
||
42 | * |
||
43 | * @var \Symfony\Component\DependencyInjection\ContainerInterface |
||
44 | */ |
||
45 | protected $container; |
||
46 | |||
47 | /** |
||
48 | * Initialize the factory with the DI container instance. |
||
49 | * |
||
50 | * @param \Symfony\Component\DependencyInjection\ContainerInterface $container The DI container instance |
||
51 | */ |
||
52 | public function __construct(ContainerInterface $container) |
||
56 | |||
57 | /** |
||
58 | * Creates and returns the serializer instance. |
||
59 | * |
||
60 | * @param \TechDivision\Import\Serializer\Configuration\SerializerConfigurationInterface $serializerConfiguration The serializer configuration |
||
61 | * |
||
62 | * @return \TechDivision\Import\Serializer\ConfigurationAwareSerializerInterface The serializer instance |
||
63 | */ |
||
64 | public function createSerializer(SerializerConfigurationInterface $serializerConfiguration) |
||
75 | } |
||
76 |
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.