Conditions | 1 |
Paths | 1 |
Total Lines | 113 |
Code Lines | 71 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
Bugs | 1 | 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 |
||
170 | public function testVariations() |
||
171 | { |
||
172 | $this->setOutputCallback(static function ($output) { |
||
173 | return null; |
||
174 | }); |
||
175 | |||
176 | ob_start(); |
||
177 | ob_implicit_flush(0); |
||
178 | |||
179 | $key = array_merge([FragmentCache::class, 'test'], ['variations' => ['ru']]); |
||
180 | |||
181 | FragmentCache::begin() |
||
182 | ->id('test') |
||
183 | ->variations(['variations' => ['ru']]) |
||
184 | ->start(); |
||
185 | |||
186 | echo 'cached fragment'; |
||
187 | |||
188 | $this->assertFalse($this->cache->has($key), 'Cached fragment should not be exist'); |
||
189 | |||
190 | echo FragmentCache::end(); |
||
191 | |||
192 | $cached = ob_get_clean(); |
||
193 | $this->assertEquals('cached fragment', $cached); |
||
194 | |||
195 | ob_start(); |
||
196 | ob_implicit_flush(0); |
||
197 | |||
198 | FragmentCache::begin() |
||
199 | ->id('test') |
||
200 | ->variations(['variations' => ['ru']]) |
||
201 | ->content(null) |
||
202 | ->start(); |
||
203 | |||
204 | $this->assertTrue($this->cache->has($key), 'Cached fragment should be exist'); |
||
205 | |||
206 | echo FragmentCache::end(); |
||
207 | |||
208 | $this->assertEquals($cached, ob_get_clean()); |
||
209 | |||
210 | $key = array_merge([FragmentCache::class, 'test'], ['variations' => ['en']]); |
||
211 | |||
212 | FragmentCache::begin() |
||
213 | ->id('test') |
||
214 | ->variations(['variations' => ['en']]) |
||
215 | ->start(); |
||
216 | |||
217 | echo 'cached fragment'; |
||
218 | |||
219 | $this->assertFalse($this->cache->has($key), 'Cached fragment should not be exist'); |
||
220 | |||
221 | echo FragmentCache::end(); |
||
222 | |||
223 | FragmentCache::begin() |
||
224 | ->id('test') |
||
225 | ->variations(['variations' => ['en']]) |
||
226 | ->content(null) |
||
227 | ->start(); |
||
228 | |||
229 | echo FragmentCache::end(); |
||
230 | |||
231 | $this->assertTrue($this->cache->has($key), 'Cached fragment should be exist'); |
||
232 | |||
233 | //without variations |
||
234 | ob_start(); |
||
235 | ob_implicit_flush(false); |
||
236 | |||
237 | $key = [FragmentCache::class, 'test']; |
||
238 | |||
239 | FragmentCache::begin() |
||
240 | ->id('test') |
||
241 | ->start(); |
||
242 | |||
243 | echo 'cached fragment'; |
||
244 | |||
245 | $this->assertFalse($this->cache->has($key), 'Cached fragment should not be exist'); |
||
246 | |||
247 | echo FragmentCache::end(); |
||
248 | |||
249 | $this->assertEquals('cached fragment', ob_get_clean()); |
||
250 | |||
251 | //with variations as a string |
||
252 | ob_start(); |
||
253 | ob_implicit_flush(0); |
||
254 | |||
255 | $key = array_merge([FragmentCache::class, 'test'], ['variations' => 'uz']); |
||
256 | |||
257 | FragmentCache::begin() |
||
258 | ->id('test') |
||
259 | ->variations(['variations' => 'uz']) |
||
260 | ->start(); |
||
261 | |||
262 | echo 'cached fragment'; |
||
263 | |||
264 | $this->assertFalse($this->cache->has($key), 'Cached fragment should not be exist'); |
||
265 | |||
266 | echo FragmentCache::end(); |
||
267 | |||
268 | $cached = ob_get_clean(); |
||
269 | $this->assertEquals('cached fragment', $cached); |
||
270 | |||
271 | ob_start(); |
||
272 | ob_implicit_flush(0); |
||
273 | |||
274 | FragmentCache::begin() |
||
275 | ->id('test') |
||
276 | ->variations(['variations' => 'uz']) |
||
277 | ->content(null) |
||
278 | ->start(); |
||
279 | echo FragmentCache::end(); |
||
280 | |||
281 | $this->assertTrue($this->cache->has($key), 'Cached fragment should be exist'); |
||
282 | $this->assertEquals($cached, ob_get_clean()); |
||
283 | } |
||
285 |