Conditions | 3 |
Paths | 4 |
Total Lines | 59 |
Code Lines | 43 |
Lines | 13 |
Ratio | 22.03 % |
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 |
||
127 | final public function testLoadMethodsCacheMiss(string $method, array $arguments, string $key, $data = null, bool $multi = false, array $additionalCalls = []) |
||
128 | { |
||
129 | $cacheItem = $this->getCacheItem($key, null); |
||
130 | $handlerMethodName = $this->getHandlerMethodName(); |
||
131 | |||
132 | $this->loggerMock->expects($this->once())->method('logCall'); |
||
133 | |||
134 | View Code Duplication | if ($multi) { |
|
135 | $this->cacheMock |
||
136 | ->expects($this->once()) |
||
137 | ->method('getItems') |
||
138 | ->with([$cacheItem->getKey()]) |
||
139 | ->willReturn([$key => $cacheItem]); |
||
140 | } else { |
||
141 | $this->cacheMock |
||
142 | ->expects($this->once()) |
||
143 | ->method('getItem') |
||
144 | ->with($cacheItem->getKey()) |
||
145 | ->willReturn($cacheItem); |
||
146 | } |
||
147 | |||
148 | $innerHandlerMock = $this->createMock($this->getHandlerClassName()); |
||
149 | $this->persistenceHandlerMock |
||
150 | ->expects($this->once()) |
||
151 | ->method($handlerMethodName) |
||
152 | ->willReturn($innerHandlerMock); |
||
153 | |||
154 | $innerHandlerMock |
||
155 | ->expects($this->once()) |
||
156 | ->method($method) |
||
157 | ->with(...$arguments) |
||
158 | ->willReturn($data); |
||
159 | |||
160 | foreach ($additionalCalls as $additionalCall) { |
||
161 | $innerHandlerMock = $this->createMock($additionalCall[1]); |
||
162 | $this->persistenceHandlerMock |
||
163 | ->expects($this->once()) |
||
164 | ->method($additionalCall[0]) |
||
165 | ->willReturn($innerHandlerMock); |
||
166 | |||
167 | $innerHandlerMock |
||
168 | ->expects($this->once()) |
||
169 | ->method($additionalCall[2]) |
||
170 | ->willReturn($additionalCall[3]); |
||
171 | } |
||
172 | |||
173 | $this->cacheMock |
||
174 | ->expects($this->once()) |
||
175 | ->method('save') |
||
176 | ->with($cacheItem); |
||
177 | |||
178 | $handler = $this->persistenceCacheHandler->$handlerMethodName(); |
||
179 | $return = call_user_func_array([$handler, $method], $arguments); |
||
180 | |||
181 | $this->assertEquals($data, $return); |
||
182 | |||
183 | // Assert use of tags would probably need custom logic as internal property is [$tag => $tag] value and we don't want to know that. |
||
184 | //$this->assertAttributeEquals([], 'tags', $cacheItem); |
||
185 | } |
||
186 | } |
||
187 |
In PHP, under loose comparison (like
==
, or!=
, orswitch
conditions), values of different types might be equal.For
string
values, the empty string''
is a special case, in particular the following results might be unexpected: