| Conditions | 4 |
| Paths | 6 |
| Total Lines | 54 |
| Code Lines | 38 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 3 | ||
| Bugs | 1 | Features | 3 |
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 |
||
| 42 | public function testRun($handler, $workload = null, $cronExpression = null, $endDateString = null, $key = null) |
||
| 43 | { |
||
| 44 | $taskBuilder = $this->prophesize(TaskBuilderInterface::class); |
||
| 45 | |||
| 46 | $input = $this->prophesize(InputInterface::class); |
||
| 47 | $output = $this->prophesize(OutputInterface::class); |
||
| 48 | |||
| 49 | $input->bind(Argument::any())->willReturn(true); |
||
| 50 | $input->validate()->willReturn(true); |
||
| 51 | $input->isInteractive()->willReturn(false); |
||
| 52 | $input->hasArgument('command')->willReturn(false); |
||
| 53 | |||
| 54 | $input->getArgument('handler')->willReturn($handler); |
||
| 55 | $input->getArgument('workload')->willReturn($workload); |
||
| 56 | $input->getOption('cron-expression')->willReturn($cronExpression); |
||
| 57 | $input->getOption('end-date')->willReturn($endDateString); |
||
| 58 | $input->getOption('key')->willReturn($key); |
||
| 59 | |||
| 60 | $scheduler = $this->prophesize(SchedulerInterface::class); |
||
| 61 | $command = new ScheduleTaskCommand('task:schedule:task', $scheduler->reveal()); |
||
| 62 | |||
| 63 | $scheduler->createTask($handler, $workload)->shouldBeCalledTimes(1)->willReturn($taskBuilder->reveal()); |
||
| 64 | |||
| 65 | if ($key !== null) { |
||
| 66 | $taskBuilder->setKey($key)->shouldBeCalled(); |
||
| 67 | } else { |
||
| 68 | $taskBuilder->setKey(Argument::any())->shouldNotBeCalled(); |
||
| 69 | } |
||
| 70 | if ($cronExpression !== null) { |
||
| 71 | $endDate = null; |
||
| 72 | if ($endDateString !== null) { |
||
| 73 | $endDate = new \DateTime($endDateString); |
||
| 74 | } |
||
| 75 | |||
| 76 | $taskBuilder->cron( |
||
| 77 | $cronExpression, |
||
| 78 | Argument::type(\DateTime::class), |
||
| 79 | Argument::that( |
||
| 80 | function ($argument) use ($endDate) { |
||
| 81 | $this->assertEquals($endDate, $argument, '', 2); |
||
| 82 | |||
| 83 | return true; |
||
| 84 | } |
||
| 85 | ) |
||
| 86 | )->shouldBeCalled() |
||
| 87 | ->willReturn($taskBuilder->reveal()); |
||
| 88 | } else { |
||
| 89 | $taskBuilder->cron(Argument::any(), Argument::any(), Argument::any())->shouldNotBeCalled() |
||
| 90 | ->willReturn($taskBuilder->reveal()); |
||
| 91 | } |
||
| 92 | $taskBuilder->schedule()->shouldBeCalledTimes(1); |
||
| 93 | |||
| 94 | $command->run($input->reveal(), $output->reveal()); |
||
| 95 | } |
||
| 96 | } |
||
| 97 |