| Conditions | 3 |
| Paths | 8 |
| Total Lines | 91 |
| Code Lines | 56 |
| 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 | while ($jobManager->getJob()) { |
||
| 14 | static::assertTrue(true); |
||
| 15 | } |
||
| 16 | |||
| 17 | // Null vs priority case |
||
| 18 | |||
| 19 | /** @var Job $job */ |
||
| 20 | $job = new static::$jobClass(static::$worker, false, null); |
||
| 21 | $job->fibonacci(1); |
||
| 22 | $id = $job->getId(); |
||
| 23 | |||
| 24 | $job2 = new static::$jobClass(static::$worker, false, null); |
||
| 25 | $job2->setPriority(1); |
||
| 26 | $job2->fibonacci(1); |
||
| 27 | $id2 = $job2->getId(); |
||
| 28 | |||
| 29 | $nextJob = $jobManager->getJob(); |
||
| 30 | static::assertEquals($id2, $nextJob->getId()); |
||
| 31 | static::assertEquals($id, $jobManager->getJob()->getId()); |
||
| 32 | |||
| 33 | // priority vs priority case |
||
| 34 | |||
| 35 | /** @var Job $job */ |
||
| 36 | $job = new static::$jobClass(static::$worker, false, null); |
||
| 37 | $job->fibonacci(1); |
||
| 38 | $job->setPriority(3); |
||
| 39 | $id = $job->getId(); |
||
| 40 | |||
| 41 | $job2 = new static::$jobClass(static::$worker, false, null); |
||
| 42 | $job2->setPriority(1); |
||
| 43 | $job2->fibonacci(1); |
||
| 44 | $id2 = $job2->getId(); |
||
| 45 | |||
| 46 | $nextJob = $jobManager->getJob(); |
||
| 47 | static::assertEquals($id2, $nextJob->getId()); |
||
| 48 | static::assertEquals($id, $jobManager->getJob()->getId()); |
||
| 49 | |||
| 50 | // priority too high case |
||
| 51 | |||
| 52 | /** @var Job $job */ |
||
| 53 | $failed = false; |
||
| 54 | try { |
||
| 55 | $job = new static::$jobClass(static::$worker, false, null); |
||
| 56 | $job->setPriority(999); |
||
| 57 | $job->fibonacci(1); |
||
| 58 | $failed = true; |
||
| 59 | } catch (\Exception $exception) { |
||
| 60 | static::assertTrue(true); |
||
| 61 | } |
||
| 62 | static::assertFalse($failed); |
||
| 63 | |||
| 64 | // Flip direction |
||
| 65 | $jobManager->setPriorityDirection(PriorityJobManager::PRIORITY_ASC); |
||
| 66 | |||
| 67 | // priority vs priority case |
||
| 68 | |||
| 69 | /** @var Job $job */ |
||
| 70 | $job = new static::$jobClass(static::$worker, false, null); |
||
| 71 | $job->fibonacci(1); |
||
| 72 | $job->setPriority(1); |
||
| 73 | $id = $job->getId(); |
||
| 74 | |||
| 75 | $job2 = new static::$jobClass(static::$worker, false, null); |
||
| 76 | $job2->setPriority(3); |
||
| 77 | $job2->fibonacci(3); |
||
| 78 | $id2 = $job2->getId(); |
||
| 79 | |||
| 80 | $nextJob = $jobManager->getJob(); |
||
| 81 | static::assertEquals($id2, $nextJob->getId()); |
||
| 82 | static::assertEquals($id, $jobManager->getJob()->getId()); |
||
| 83 | |||
| 84 | // Null vs priority case |
||
| 85 | |||
| 86 | /** @var Job $job */ |
||
| 87 | $job = new static::$jobClass(static::$worker, false, null); |
||
| 88 | $job->fibonacci(1); |
||
| 89 | $id = $job->getId(); |
||
| 90 | |||
| 91 | $job2 = new static::$jobClass(static::$worker, false, null); |
||
| 92 | $job2->setPriority(1); |
||
| 93 | $job2->fibonacci(1); |
||
| 94 | $id2 = $job2->getId(); |
||
| 95 | |||
| 96 | $nextJob = $jobManager->getJob(); |
||
| 97 | static::assertEquals($id2, $nextJob->getId()); |
||
| 98 | static::assertEquals($id, $jobManager->getJob()->getId()); |
||
| 99 | } |
||
| 100 | } |
||
| 101 |