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 ILogger |
||
| 44 | */ |
||
| 45 | private $logger; |
||
| 46 | |||
| 47 | /** |
||
| 48 | * |
||
| 49 | * @var IL10N |
||
| 50 | */ |
||
| 51 | private $l10n; |
||
| 52 | |||
| 53 | /** |
||
| 54 | * |
||
| 55 | * @var string |
||
| 56 | */ |
||
| 57 | private $redisHost; |
||
| 58 | |||
| 59 | /** |
||
| 60 | * |
||
| 61 | * @var integer |
||
| 62 | */ |
||
| 63 | private $redisPort; |
||
| 64 | |||
| 65 | /** |
||
| 66 | * |
||
| 67 | * @var integer |
||
| 68 | */ |
||
| 69 | private $redisDb; |
||
| 70 | |||
| 71 | /** |
||
| 72 | * |
||
| 73 | * @var string |
||
| 74 | */ |
||
| 75 | private $appName = 'ocr'; |
||
| 76 | |||
| 77 | /** |
||
| 78 | * QueueService constructor. |
||
| 79 | * |
||
| 80 | * @param OcrJobMapper $mapper |
||
| 81 | * @param IConfig $config |
||
| 82 | * @param IL10N $l10n |
||
| 83 | * @param ILogger $logger |
||
| 84 | */ |
||
| 85 | public function __construct(OcrJobMapper $mapper, IConfig $config, IL10N $l10n, ILogger $logger) { |
||
| 94 | |||
| 95 | /** |
||
| 96 | * Inits the client and sends the task to the background worker (async) |
||
| 97 | * |
||
| 98 | * @param OcrJob $job |
||
| 99 | * @param string[] $languages |
||
| 100 | * @param string $occDir |
||
| 101 | */ |
||
| 102 | public function sendJob($job, $languages, $occDir) { |
||
| 126 | |||
| 127 | /** |
||
| 128 | * Retrieves all finished jobs from redis and returns them. |
||
| 129 | * |
||
| 130 | * @return string[] |
||
| 131 | */ |
||
| 132 | public function readingFinishedJobs() { |
||
| 143 | |||
| 144 | /** |
||
| 145 | * Setup the Redis instance and return to whom ever it needs. |
||
| 146 | * |
||
| 147 | * @throws NotFoundException |
||
| 148 | * @return \Redis |
||
| 149 | */ |
||
| 150 | private function setupRedisInstance() { |
||
| 169 | |||
| 170 | /** |
||
| 171 | * Handle the possible thrown Exceptions from all methods of this class. |
||
| 172 | * |
||
| 173 | * @param Exception $e |
||
| 174 | * @throws Exception |
||
| 175 | * @throws NotFoundException |
||
| 176 | */ |
||
| 177 | View Code Duplication | private function handleException($e) { |
|
| 188 | } |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.