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 |
||
35 | View Code Duplication | class PrefixedCachePoolFactory |
|
|
|||
36 | { |
||
37 | |||
38 | /** |
||
39 | * The configuration instance. |
||
40 | * |
||
41 | * @var \TechDivision\Import\ConfigurationInterface |
||
42 | */ |
||
43 | protected $configuration; |
||
44 | |||
45 | /** |
||
46 | * The cache factory instance. |
||
47 | * |
||
48 | * @var \TechDivision\Import\Connection\CachePoolFactoryInterface |
||
49 | */ |
||
50 | protected $cachePoolFactory; |
||
51 | |||
52 | /** |
||
53 | * Initialize the cache adapter factory with the passed configuration instances. |
||
54 | * . |
||
55 | * @param \TechDivision\Import\ConfigurationInterface $configuration The configuration instance |
||
56 | * @param \TechDivision\Import\Connection\CachePoolFactoryInterface $cachePoolFactory The cache factory instance |
||
57 | */ |
||
58 | public function __construct(ConfigurationInterface $configuration, CachePoolFactoryInterface $cachePoolFactory) |
||
63 | |||
64 | /** |
||
65 | * Creates and returns the cache pool instance. |
||
66 | * |
||
67 | * @return \Cache\Prefixed\PrefixedCachePool The prefixed cache pool instance |
||
68 | */ |
||
69 | public function createCachePool() |
||
73 | } |
||
74 |
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.