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 |
||
39 | public function testExecute(): void |
||
40 | { |
||
41 | $token = $this->createMock(AccessToken::class); |
||
42 | |||
43 | $app = $this->createMock(FacebookApp::class); |
||
44 | $app->expects($this->once())->method('getAccessToken') |
||
45 | ->willReturn($token) |
||
46 | ; |
||
47 | |||
48 | $this->facebook->expects($this->once())->method('getApp') |
||
49 | ->willReturn($app) |
||
50 | ; |
||
51 | |||
52 | $feedResponse = [ |
||
53 | ['foo' => 'bar'], |
||
54 | ]; |
||
55 | |||
56 | $edge = $this->createMock(GraphEdge::class); |
||
57 | $edge->expects($this->once())->method('asArray') |
||
58 | ->willReturn($feedResponse) |
||
59 | ; |
||
60 | |||
61 | $response = $this->createMock(FacebookResponse::class); |
||
62 | $response->expects($this->once())->method('getGraphEdge') |
||
63 | ->willReturn($edge) |
||
64 | ; |
||
65 | |||
66 | $this->facebook->method('get') |
||
67 | ->with($this->equalTo('/0815/feed?fields=type,message,description,permalink_url,picture,created_time'), $this->equalTo($token)) |
||
68 | ->willReturn($response) |
||
69 | ; |
||
70 | |||
71 | $block = new Block(); |
||
72 | |||
73 | $blockContext = new BlockContext($block, [ |
||
74 | 'title' => null, |
||
75 | 'translation_domain' => null, |
||
76 | 'template' => '@Core23Facebook/Block/block_page_feed.html.twig', |
||
77 | 'id' => '0815', |
||
78 | 'fields' => 'type,message,description,permalink_url,picture,created_time', |
||
79 | ]); |
||
80 | |||
81 | $blockService = new PageFeedBlockService('block.service', $this->templating, $this->facebook); |
||
|
|||
82 | $blockService->execute($blockContext); |
||
83 | |||
84 | $this->assertSame('@Core23Facebook/Block/block_page_feed.html.twig', $this->templating->view); |
||
85 | |||
86 | $this->assertSame($blockContext, $this->templating->parameters['context']); |
||
87 | $this->assertInternalType('array', $this->templating->parameters['settings']); |
||
88 | $this->assertInstanceOf(BlockInterface::class, $this->templating->parameters['block']); |
||
89 | |||
90 | $this->assertSame($feedResponse, $this->templating->parameters['feed']); |
||
91 | } |
||
92 | |||
179 |
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: