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 |
||
| 17 | abstract class BaseJobManager extends PriorityJobManager |
||
| 18 | { |
||
| 19 | use JobIdTrait; |
||
| 20 | use VerifyTrait; |
||
| 21 | |||
| 22 | /** @var RedisInterface */ |
||
| 23 | protected $redis; |
||
| 24 | |||
| 25 | /** @var string */ |
||
| 26 | protected $cacheKeyPrefix; |
||
| 27 | |||
| 28 | protected $hostname; |
||
| 29 | protected $pid; |
||
| 30 | |||
| 31 | /** |
||
| 32 | * @param string $cacheKeyPrefix |
||
| 33 | */ |
||
| 34 | 3 | public function __construct(RunManager $runManager, JobTimingManager $jobTimingManager, $jobClass, $cacheKeyPrefix) |
|
| 42 | |||
| 43 | public function setRedis(RedisInterface $redis) |
||
| 47 | |||
| 48 | 28 | protected function getJobCacheKey($jobId) |
|
| 52 | |||
| 53 | /** |
||
| 54 | * @param string $jobCrc |
||
| 55 | */ |
||
| 56 | 28 | protected function getJobCrcHashKey($jobCrc) |
|
| 60 | |||
| 61 | 14 | protected function getPriorityQueueCacheKey() |
|
| 65 | |||
| 66 | 28 | protected function getWhenQueueCacheKey() |
|
| 70 | |||
| 71 | 18 | protected function getStatusCacheKey() |
|
| 75 | |||
| 76 | abstract protected function saveJob(Job $job); |
||
| 77 | |||
| 78 | 9 | View Code Duplication | public function resetJob(RetryableJob $job) |
| 92 | |||
| 93 | 3 | public function deleteJob(\Dtc\QueueBundle\Model\Job $job) |
|
| 104 | } |
||
| 105 |
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.