Conditions | 3 |
Paths | 1 |
Total Lines | 53 |
Code Lines | 35 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 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 |
||
94 | public function testShouldAddPagination() |
||
95 | { |
||
96 | $this->containerBuilder |
||
97 | ->expects($this->once()) |
||
98 | ->method('getExtensionConfig') |
||
99 | ->with('api_service') |
||
100 | ->willReturn([ |
||
101 | [ |
||
102 | 'pagination' => [ |
||
103 | 'hal' => [ |
||
104 | 'page' => '_links.self.href.page', |
||
105 | 'perPage' => 'itemsPerPage', |
||
106 | 'totalPages' => '_links.last.href.page', |
||
107 | 'totalItems' => 'totalItems', |
||
108 | ], |
||
109 | ], |
||
110 | ] |
||
111 | ]) |
||
112 | ; |
||
113 | $this->containerBuilder |
||
114 | ->expects($this->once()) |
||
115 | ->method('findTaggedServiceIds') |
||
116 | ->with('api_service.pagination_provider') |
||
117 | ->willReturn([ |
||
118 | 'foo' => [['provider' => 'hal']] |
||
119 | ]) |
||
120 | ; |
||
121 | $this->containerBuilder |
||
122 | ->expects($this->exactly(2)) |
||
123 | ->method('getDefinition') |
||
124 | ->willReturnCallback(function ($id) { |
||
125 | $this->assertTrue(\in_array($id, ['api_service.pagination_provider.chain', 'foo'])); |
||
126 | |||
127 | if ('api_service.pagination_provider.chain' === $id) { |
||
128 | $this->pagination->expects($this->once())->method('replaceArgument')->willReturnCallback(function ($key, $argument) { |
||
129 | $this->assertSame(0, $key); |
||
130 | $this->assertIsArray($argument); |
||
131 | $this->assertNotEmpty($argument); |
||
132 | }); |
||
133 | } else if ('foo' === $id) { |
||
134 | $this->pagination->expects($this->exactly(2))->method('replaceArgument')->willReturnCallback(function ($key, $argument) { |
||
135 | $this->assertSame(0, $key); |
||
136 | $this->assertIsArray($argument); |
||
137 | $this->assertNotEmpty($argument); |
||
138 | }); |
||
139 | } |
||
140 | |||
141 | return $this->pagination; |
||
142 | }) |
||
143 | ; |
||
144 | |||
145 | $compiler = new PaginatorCompilerPass(); |
||
146 | $compiler->process($this->containerBuilder); |
||
147 | } |
||
149 |