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 |
||
| 27 | class RedisService { |
||
| 28 | |||
| 29 | /** |
||
| 30 | * |
||
| 31 | * @var IConfig |
||
| 32 | */ |
||
| 33 | private $config; |
||
| 34 | |||
| 35 | /** |
||
| 36 | * |
||
| 37 | * @var OcrJobMapper |
||
| 38 | */ |
||
| 39 | private $mapper; |
||
| 40 | |||
| 41 | /** |
||
| 42 | * |
||
| 43 | * @var FileService |
||
| 44 | */ |
||
| 45 | private $fileService; |
||
| 46 | |||
| 47 | /** |
||
| 48 | * |
||
| 49 | * @var ILogger |
||
| 50 | */ |
||
| 51 | private $logger; |
||
| 52 | |||
| 53 | /** |
||
| 54 | * |
||
| 55 | * @var IL10N |
||
| 56 | */ |
||
| 57 | private $l10n; |
||
| 58 | |||
| 59 | /** |
||
| 60 | * |
||
| 61 | * @var string |
||
| 62 | */ |
||
| 63 | private $redisHost; |
||
| 64 | |||
| 65 | /** |
||
| 66 | * |
||
| 67 | * @var integer |
||
| 68 | */ |
||
| 69 | private $redisPort; |
||
| 70 | |||
| 71 | /** |
||
| 72 | * |
||
| 73 | * @var integer |
||
| 74 | */ |
||
| 75 | private $redisDb; |
||
| 76 | |||
| 77 | /** |
||
| 78 | * |
||
| 79 | * @var string |
||
| 80 | */ |
||
| 81 | private $appName = 'ocr'; |
||
| 82 | |||
| 83 | /** |
||
| 84 | * QueueService constructor. |
||
| 85 | * |
||
| 86 | * @param OcrJobMapper $mapper |
||
| 87 | * @param FileService $fileService |
||
| 88 | * @param IConfig $config |
||
| 89 | * @param IL10N $l10n |
||
| 90 | * @param ILogger $logger |
||
| 91 | */ |
||
| 92 | public function __construct(OcrJobMapper $mapper, FileService $fileService, IConfig $config, IL10N $l10n, ILogger $logger) { |
||
| 102 | |||
| 103 | /** |
||
| 104 | * Inits the client and sends the task to the background worker (async) |
||
| 105 | * |
||
| 106 | * @param OcrJob $job |
||
| 107 | * @param string[] $languages |
||
| 108 | * @param string $occDir |
||
| 109 | */ |
||
| 110 | public function sendJob($job, $languages, $occDir) { |
||
| 134 | |||
| 135 | /** |
||
| 136 | * Retrieves all finished jobs from redis and returns them. |
||
| 137 | * |
||
| 138 | * @return string[] |
||
| 139 | */ |
||
| 140 | public function readingFinishedJobs() { |
||
| 153 | |||
| 154 | /** |
||
| 155 | * Setup the Redis instance and return to whom ever it needs. |
||
| 156 | * |
||
| 157 | * @throws NotFoundException |
||
| 158 | * @return \Redis |
||
| 159 | */ |
||
| 160 | private function setupRedisInstance() { |
||
| 179 | |||
| 180 | /** |
||
| 181 | * Handle the possible thrown Exceptions from all methods of this class. |
||
| 182 | * |
||
| 183 | * @param Exception $e |
||
| 184 | * @throws Exception |
||
| 185 | * @throws NotFoundException |
||
| 186 | */ |
||
| 187 | private function handleException($e) { |
||
| 193 | } |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.