| Conditions | 4 |
| Paths | 8 |
| Total Lines | 94 |
| Code Lines | 58 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 9 | public function testPriorityJobs() |
||
| 10 | { |
||
| 11 | $jobManager = static::$jobManager; |
||
| 12 | |||
| 13 | // Drain the queue |
||
| 14 | $limit = 99999; |
||
| 15 | while ($jobManager->getJob() && $limit--) { |
||
| 16 | static::assertTrue(true); |
||
| 17 | } |
||
| 18 | self::assertGreaterThan(0, $limit); |
||
| 19 | |||
| 20 | // Null vs priority case |
||
| 21 | |||
| 22 | /** @var Job $job */ |
||
| 23 | $job = new static::$jobClass(static::$worker, false, null); |
||
| 24 | $job->fibonacci(1); |
||
| 25 | $id = $job->getId(); |
||
| 26 | |||
| 27 | $job2 = new static::$jobClass(static::$worker, false, null); |
||
| 28 | $job2->setPriority(1); |
||
| 29 | $job2->fibonacci(1); |
||
| 30 | $id2 = $job2->getId(); |
||
| 31 | |||
| 32 | $nextJob = $jobManager->getJob(); |
||
| 33 | static::assertEquals($id2, $nextJob->getId()); |
||
| 34 | static::assertEquals($id, $jobManager->getJob()->getId()); |
||
| 35 | |||
| 36 | // priority vs priority case |
||
| 37 | |||
| 38 | /** @var Job $job */ |
||
| 39 | $job = new static::$jobClass(static::$worker, false, null); |
||
| 40 | $job->fibonacci(1); |
||
| 41 | $job->setPriority(3); |
||
| 42 | $id = $job->getId(); |
||
| 43 | |||
| 44 | $job2 = new static::$jobClass(static::$worker, false, null); |
||
| 45 | $job2->setPriority(1); |
||
| 46 | $job2->fibonacci(1); |
||
| 47 | $id2 = $job2->getId(); |
||
| 48 | |||
| 49 | $nextJob = $jobManager->getJob(); |
||
| 50 | static::assertEquals($id2, $nextJob->getId()); |
||
| 51 | static::assertEquals($id, $jobManager->getJob()->getId()); |
||
| 52 | |||
| 53 | // priority too high case |
||
| 54 | |||
| 55 | /** @var Job $job */ |
||
| 56 | $failed = false; |
||
| 57 | try { |
||
| 58 | $job = new static::$jobClass(static::$worker, false, null); |
||
| 59 | $job->setPriority(999); |
||
| 60 | $job->fibonacci(1); |
||
| 61 | $failed = true; |
||
| 62 | } catch (\Exception $exception) { |
||
| 63 | static::assertTrue(true); |
||
| 64 | } |
||
| 65 | static::assertFalse($failed); |
||
| 66 | |||
| 67 | // Flip direction |
||
| 68 | $jobManager->setPriorityDirection(PriorityJobManager::PRIORITY_ASC); |
||
| 69 | |||
| 70 | // priority vs priority case |
||
| 71 | |||
| 72 | /** @var Job $job */ |
||
| 73 | $job = new static::$jobClass(static::$worker, false, null); |
||
| 74 | $job->fibonacci(1); |
||
| 75 | $job->setPriority(1); |
||
| 76 | $id = $job->getId(); |
||
| 77 | |||
| 78 | $job2 = new static::$jobClass(static::$worker, false, null); |
||
| 79 | $job2->setPriority(3); |
||
| 80 | $job2->fibonacci(3); |
||
| 81 | $id2 = $job2->getId(); |
||
| 82 | |||
| 83 | $nextJob = $jobManager->getJob(); |
||
| 84 | static::assertEquals($id2, $nextJob->getId()); |
||
| 85 | static::assertEquals($id, $jobManager->getJob()->getId()); |
||
| 86 | |||
| 87 | // Null vs priority case |
||
| 88 | |||
| 89 | /** @var Job $job */ |
||
| 90 | $job = new static::$jobClass(static::$worker, false, null); |
||
| 91 | $job->fibonacci(1); |
||
| 92 | $id = $job->getId(); |
||
| 93 | |||
| 94 | $job2 = new static::$jobClass(static::$worker, false, null); |
||
| 95 | $job2->setPriority(1); |
||
| 96 | $job2->fibonacci(1); |
||
| 97 | $id2 = $job2->getId(); |
||
| 98 | |||
| 99 | $nextJob = $jobManager->getJob(); |
||
| 100 | static::assertEquals($id2, $nextJob->getId()); |
||
| 101 | static::assertEquals($id, $jobManager->getJob()->getId()); |
||
| 102 | } |
||
| 103 | } |
||
| 104 |