| Conditions | 1 |
| Paths | 1 |
| Total Lines | 53 |
| 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 |
||
| 38 | public function testExecute(): void |
||
| 39 | { |
||
| 40 | $token = $this->createMock(AccessToken::class); |
||
| 41 | |||
| 42 | $app = $this->createMock(FacebookApp::class); |
||
| 43 | $app->expects(static::once())->method('getAccessToken') |
||
| 44 | ->willReturn($token) |
||
| 45 | ; |
||
| 46 | |||
| 47 | $this->facebook->expects(static::once())->method('getApp') |
||
| 48 | ->willReturn($app) |
||
| 49 | ; |
||
| 50 | |||
| 51 | $feedResponse = [ |
||
| 52 | ['foo' => 'bar'], |
||
| 53 | ]; |
||
| 54 | |||
| 55 | $edge = $this->createMock(GraphEdge::class); |
||
| 56 | $edge->expects(static::once())->method('asArray') |
||
| 57 | ->willReturn($feedResponse) |
||
| 58 | ; |
||
| 59 | |||
| 60 | $response = $this->createMock(FacebookResponse::class); |
||
| 61 | $response->expects(static::once())->method('getGraphEdge') |
||
| 62 | ->willReturn($edge) |
||
| 63 | ; |
||
| 64 | |||
| 65 | $this->facebook->method('get') |
||
| 66 | ->with(static::equalTo('/0815/feed?fields=type,message,description,permalink_url,picture,created_time'), static::equalTo($token)) |
||
| 67 | ->willReturn($response) |
||
| 68 | ; |
||
| 69 | |||
| 70 | $block = new Block(); |
||
| 71 | |||
| 72 | $blockContext = new BlockContext($block, [ |
||
| 73 | 'title' => null, |
||
| 74 | 'translation_domain' => null, |
||
| 75 | 'template' => '@Core23Facebook/Block/block_page_feed.html.twig', |
||
| 76 | 'id' => '0815', |
||
| 77 | 'fields' => 'type,message,description,permalink_url,picture,created_time', |
||
| 78 | ]); |
||
| 79 | |||
| 80 | $blockService = new PageFeedBlockService('block.service', $this->templating, $this->facebook); |
||
|
|
|||
| 81 | $blockService->execute($blockContext); |
||
| 82 | |||
| 83 | static::assertSame('@Core23Facebook/Block/block_page_feed.html.twig', $this->templating->view); |
||
| 84 | |||
| 85 | static::assertSame($blockContext, $this->templating->parameters['context']); |
||
| 86 | static::assertIsArray($this->templating->parameters['settings']); |
||
| 87 | static::assertInstanceOf(BlockInterface::class, $this->templating->parameters['block']); |
||
| 88 | |||
| 89 | static::assertSame($feedResponse, $this->templating->parameters['feed']); |
||
| 90 | } |
||
| 91 | |||
| 175 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: