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 |
||
26 | class RedisUtil { |
||
27 | |||
28 | /** |
||
29 | * |
||
30 | * @var IL10N |
||
31 | */ |
||
32 | private $l10n; |
||
33 | |||
34 | /** |
||
35 | * |
||
36 | * @var ILogger |
||
37 | */ |
||
38 | private $logger; |
||
39 | |||
40 | /** |
||
41 | * |
||
42 | * @var IConfig |
||
43 | */ |
||
44 | private $config; |
||
45 | |||
46 | /** |
||
47 | * |
||
48 | * @var string |
||
49 | */ |
||
50 | private $appName = 'ocr'; |
||
51 | |||
52 | /** |
||
53 | * |
||
54 | * @param IL10N $l10n |
||
55 | * @param ILogger $logger |
||
56 | * @param IConfig $config |
||
57 | */ |
||
58 | 7 | public function __construct(IL10N $l10n, ILogger $logger, IConfig $config) { |
|
63 | |||
64 | /** |
||
65 | * Setup the Redis instance and return to whom ever it needs. |
||
66 | * @codeCoverageIgnore |
||
67 | * |
||
68 | * @throws NotFoundException |
||
69 | * @return \Redis |
||
70 | */ |
||
71 | public function setupRedisInstance() { |
||
103 | } |
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.