| Conditions | 1 |
| Paths | 1 |
| Total Lines | 52 |
| 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 |
||
| 43 | public function testTermFallbackCacheFactoryCachesInMemory(): void { |
||
| 44 | $sharedCacheType = CACHE_DB; |
||
| 45 | $cacheSecret = 'secret'; |
||
| 46 | |||
| 47 | $mockSharedCache = $this->createMock( BagOStuff::class ); |
||
| 48 | $mockInMemoryCache = $this->createMock( CachedBagOStuff::class ); |
||
| 49 | $mockCache = $this->createMock( SimpleCacheWithBagOStuff::class ); |
||
| 50 | $mockStatsdRecordingSimpleCache = $this->createMock( StatsdRecordingSimpleCache::class ); |
||
| 51 | |||
| 52 | $serviceFactory = $this->createMock( TermFallbackCacheServiceFactory::class ); |
||
| 53 | |||
| 54 | $serviceFactory->expects( $this->once() ) |
||
| 55 | ->method( 'newSharedCache' ) |
||
| 56 | ->with( $sharedCacheType ) |
||
| 57 | ->willReturn( $mockSharedCache ); |
||
| 58 | |||
| 59 | $serviceFactory->expects( $this->once() ) |
||
| 60 | ->method( 'newInMemoryCache' ) |
||
| 61 | ->with( $mockSharedCache ) |
||
| 62 | ->willReturn( $mockInMemoryCache ); |
||
| 63 | |||
| 64 | $mockCache->expects( $this->once() ) |
||
| 65 | ->method( 'setLogger' ) |
||
| 66 | ->with( $this->mockLogger ); |
||
| 67 | $serviceFactory->expects( $this->once() ) |
||
| 68 | ->method( 'newCache' ) |
||
| 69 | ->with( $mockInMemoryCache, 'wikibase.repo.formatter.', $cacheSecret ) |
||
| 70 | ->willReturn( $mockCache ); |
||
| 71 | |||
| 72 | $serviceFactory->expects( $this->once() ) |
||
| 73 | ->method( 'newStatsdRecordingCache' ) |
||
| 74 | ->with( |
||
| 75 | $mockCache, |
||
| 76 | $this->mockIBufferingStatsdDataFactory, |
||
| 77 | [ |
||
| 78 | 'miss' => 'wikibase.repo.formatterCache.miss', |
||
| 79 | 'hit' => 'wikibase.repo.formatterCache.hit', |
||
| 80 | ] |
||
| 81 | ) |
||
| 82 | ->willReturn( $mockStatsdRecordingSimpleCache ); |
||
| 83 | |||
| 84 | $factory = new TermFallbackCacheFactory( |
||
| 85 | $sharedCacheType, |
||
| 86 | $this->mockLogger, |
||
| 87 | $this->mockIBufferingStatsdDataFactory, |
||
| 88 | $cacheSecret, |
||
| 89 | $serviceFactory, |
||
| 90 | null |
||
| 91 | ); |
||
| 92 | |||
| 93 | $this->assertInstanceOf( StatsdRecordingSimpleCache::class, $factory->getTermFallbackCache() ); |
||
| 94 | } |
||
| 95 | |||
| 184 |