| Conditions | 4 |
| Paths | 8 |
| Total Lines | 65 |
| Lines | 32 |
| Ratio | 49.23 % |
| 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 |
||
| 138 | final public function testLoadMethodsCacheMiss(string $method, array $arguments, string $key, $data = null, bool $multi = false, array $additionalCalls = [], bool $logHitMiss = false) |
||
| 139 | { |
||
| 140 | $cacheItem = $this->getCacheItem($key, null); |
||
| 141 | $handlerMethodName = $this->getHandlerMethodName(); |
||
| 142 | |||
| 143 | View Code Duplication | If ($logHitMiss) { |
|
| 144 | $this->loggerMock->expects($this->once())->method('logCacheMiss'); |
||
| 145 | $this->loggerMock->expects($this->never())->method('logCall'); |
||
| 146 | $this->loggerMock->expects($this->never())->method('logCacheHit'); |
||
| 147 | } else { |
||
| 148 | $this->loggerMock->expects($this->once())->method('logCall'); |
||
| 149 | } |
||
| 150 | |||
| 151 | View Code Duplication | if ($multi) { |
|
| 152 | $this->cacheMock |
||
| 153 | ->expects($this->once()) |
||
| 154 | ->method('getItems') |
||
| 155 | ->with([$cacheItem->getKey()]) |
||
| 156 | ->willReturn([$key => $cacheItem]); |
||
| 157 | } else { |
||
| 158 | $this->cacheMock |
||
| 159 | ->expects($this->once()) |
||
| 160 | ->method('getItem') |
||
| 161 | ->with($cacheItem->getKey()) |
||
| 162 | ->willReturn($cacheItem); |
||
| 163 | } |
||
| 164 | |||
| 165 | $innerHandlerMock = $this->createMock($this->getHandlerClassName()); |
||
| 166 | $this->persistenceHandlerMock |
||
| 167 | ->expects($this->once()) |
||
| 168 | ->method($handlerMethodName) |
||
| 169 | ->willReturn($innerHandlerMock); |
||
| 170 | |||
| 171 | $innerHandlerMock |
||
| 172 | ->expects($this->once()) |
||
| 173 | ->method($method) |
||
| 174 | ->with(...$arguments) |
||
| 175 | ->willReturn($data); |
||
| 176 | |||
| 177 | View Code Duplication | foreach ($additionalCalls as $additionalCall) { |
|
| 178 | $innerHandlerMock = $this->createMock($additionalCall[1]); |
||
| 179 | $this->persistenceHandlerMock |
||
| 180 | ->expects($this->once()) |
||
| 181 | ->method($additionalCall[0]) |
||
| 182 | ->willReturn($innerHandlerMock); |
||
| 183 | |||
| 184 | $innerHandlerMock |
||
| 185 | ->expects($this->once()) |
||
| 186 | ->method($additionalCall[2]) |
||
| 187 | ->willReturn($additionalCall[3]); |
||
| 188 | } |
||
| 189 | |||
| 190 | $this->cacheMock |
||
| 191 | ->expects($this->once()) |
||
| 192 | ->method('save') |
||
| 193 | ->with($cacheItem); |
||
| 194 | |||
| 195 | $handler = $this->persistenceCacheHandler->$handlerMethodName(); |
||
| 196 | $return = call_user_func_array([$handler, $method], $arguments); |
||
| 197 | |||
| 198 | $this->assertEquals($data, $return); |
||
| 199 | |||
| 200 | // Assert use of tags would probably need custom logic as internal property is [$tag => $tag] value and we don't want to know that. |
||
| 201 | //$this->assertAttributeEquals([], 'tags', $cacheItem); |
||
| 202 | } |
||
| 203 | } |
||
| 204 |
In PHP, under loose comparison (like
==, or!=, orswitchconditions), values of different types might be equal.For
stringvalues, the empty string''is a special case, in particular the following results might be unexpected: