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 |
||
| 20 | class PhpRedisJobManagerTest extends JobManagerTest |
||
| 21 | { |
||
| 22 | use PriorityTestTrait; |
||
| 23 | use AutoRetryTrait; |
||
| 24 | public static $connection; |
||
| 25 | |||
| 26 | public static function setUpBeforeClass() |
||
| 27 | { |
||
| 28 | $host = getenv('REDIS_HOST'); |
||
| 29 | $port = getenv('REDIS_PORT') ?: 6379; |
||
| 30 | $jobTimingClass = JobTiming::class; |
||
| 31 | $runClass = Run::class; |
||
| 32 | $redis = new \Redis(); |
||
| 33 | $redis->connect($host, $port); |
||
| 34 | $redis->flushAll(); |
||
| 35 | $phpredis = new PhpRedis($redis); |
||
| 36 | |||
| 37 | self::$jobTimingManager = new JobTimingManager($jobTimingClass, false); |
||
| 38 | self::$runManager = new RunManager($runClass); |
||
| 39 | self::$jobManager = new JobManager( |
||
| 40 | self::$runManager, |
||
| 41 | self::$jobTimingManager, |
||
| 42 | \Dtc\QueueBundle\Redis\Job::class, |
||
| 43 | 'test_cache_key' |
||
| 44 | ); |
||
| 45 | self::$jobManager->setRedis($phpredis); |
||
| 46 | self::$jobManager->setMaxPriority(255); |
||
| 47 | self::$worker = new FibonacciWorker(); |
||
| 48 | parent::setUpBeforeClass(); |
||
| 49 | } |
||
| 50 | } |
||
| 51 |