| Conditions | 1 |
| Paths | 1 |
| Total Lines | 58 |
| Code Lines | 38 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 3 | ||
| Bugs | 1 | Features | 2 |
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 |
||
| 13 | public function testProcess() |
||
| 14 | { |
||
| 15 | $containerBuilder = $this->prophesize(ContainerBuilder::class); |
||
| 16 | $schedulerDefinition = $this->prophesize(Definition::class); |
||
| 17 | $handler1Definition = $this->prophesize(Definition::class); |
||
| 18 | $handler2Definition = $this->prophesize(Definition::class); |
||
| 19 | |||
| 20 | $containerBuilder->has(TaskCompilerPass::SCHEDULER_ID)->willReturn(true); |
||
| 21 | $containerBuilder->getDefinition(TaskCompilerPass::SCHEDULER_ID)->willReturn($schedulerDefinition->reveal()); |
||
| 22 | $containerBuilder->getDefinition('id-1')->willReturn($handler1Definition->reveal()); |
||
| 23 | $containerBuilder->getDefinition('id-2')->willReturn($handler2Definition->reveal()); |
||
| 24 | |||
| 25 | $containerBuilder->findTaggedServiceIds(TaskCompilerPass::INTERVAL_TAG) |
||
| 26 | ->willReturn( |
||
| 27 | [ |
||
| 28 | 'id-1' => [ |
||
| 29 | [ |
||
| 30 | TaskCompilerPass::INTERVAL_ATTRIBUTE => 'daily', |
||
| 31 | TaskCompilerPass::WORKLOAD_ATTRIBUTE => 'test-workload', |
||
| 32 | TaskCompilerPass::KEY_ATTRIBUTE => 'test-key' |
||
| 33 | ], |
||
| 34 | ], |
||
| 35 | 'id-2' => [ |
||
| 36 | [ |
||
| 37 | TaskCompilerPass::INTERVAL_ATTRIBUTE => 'daily', |
||
| 38 | TaskCompilerPass::KEY_ATTRIBUTE => 'test-key-1' |
||
| 39 | ], |
||
| 40 | [ |
||
| 41 | TaskCompilerPass::INTERVAL_ATTRIBUTE => 'daily', |
||
| 42 | TaskCompilerPass::WORKLOAD_ATTRIBUTE => 'test-workload-2' |
||
| 43 | ], |
||
| 44 | ], |
||
| 45 | ] |
||
| 46 | ); |
||
| 47 | |||
| 48 | $handler1Definition->getTag(HandlerCompilerPass::HANDLER_TAG)->willReturn( |
||
| 49 | [[HandlerCompilerPass::HANDLER_NAME_ATTRIBUTE => 'handler-1']] |
||
| 50 | ); |
||
| 51 | $handler2Definition->getTag(HandlerCompilerPass::HANDLER_TAG)->willReturn( |
||
| 52 | [[HandlerCompilerPass::HANDLER_NAME_ATTRIBUTE => 'handler-2']] |
||
| 53 | ); |
||
| 54 | |||
| 55 | $compilerPass = new TaskCompilerPass(); |
||
| 56 | $compilerPass->process($containerBuilder->reveal()); |
||
| 57 | |||
| 58 | $schedulerDefinition->addMethodCall( |
||
| 59 | TaskCompilerPass::CREATE_FUNCTION_NAME, |
||
| 60 | ['handler-1', 'test-workload', 'daily', 'test-key'] |
||
| 61 | )->shouldBeCalledTimes(1); |
||
| 62 | $schedulerDefinition->addMethodCall( |
||
| 63 | TaskCompilerPass::CREATE_FUNCTION_NAME, |
||
| 64 | ['handler-2', null, 'daily', 'test-key-1'] |
||
| 65 | )->shouldBeCalledTimes(1); |
||
| 66 | $schedulerDefinition->addMethodCall( |
||
| 67 | TaskCompilerPass::CREATE_FUNCTION_NAME, |
||
| 68 | ['handler-2', 'test-workload-2', 'daily', 'handler-2_daily_s:15:"test-workload-2";'] |
||
| 69 | )->shouldBeCalledTimes(1); |
||
| 70 | } |
||
| 71 | } |
||
| 72 |