Conditions | 1 |
Paths | 1 |
Total Lines | 52 |
Code Lines | 38 |
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 |
||
48 | public function testRecover() |
||
49 | { |
||
50 | $originalLocationId = 6; |
||
51 | $targetLocationId = 2; |
||
52 | $contentId = 42; |
||
53 | |||
54 | $tags = [ |
||
55 | 'content-' . $contentId, |
||
56 | 'content-fields-' . $contentId, |
||
57 | 'location-' . $originalLocationId, |
||
58 | 'location-path-' . $originalLocationId, |
||
59 | ]; |
||
60 | |||
61 | $handlerMethodName = $this->getHandlerMethodName(); |
||
62 | |||
63 | $this->loggerMock->expects($this->once())->method('logCall'); |
||
64 | |||
65 | $innerHandler = $this->createMock($this->getHandlerClassName()); |
||
66 | $contentHandlerMock = $this->createMock(ContentHandler::class); |
||
67 | $locationHandlerMock = $this->createMock(LocationHandler::class); |
||
68 | |||
69 | $locationHandlerMock |
||
70 | ->method('load') |
||
71 | ->will($this->returnValue(new Location(['id' => $originalLocationId, 'contentId' => $contentId]))); |
||
72 | |||
73 | $this->persistenceHandlerMock |
||
74 | ->method('contentHandler') |
||
75 | ->will($this->returnValue($contentHandlerMock)); |
||
76 | |||
77 | $this->persistenceHandlerMock |
||
78 | ->method('locationHandler') |
||
79 | ->will($this->returnValue($locationHandlerMock)); |
||
80 | |||
81 | $this->persistenceHandlerMock |
||
82 | ->expects($this->once()) |
||
83 | ->method($handlerMethodName) |
||
84 | ->will($this->returnValue($innerHandler)); |
||
85 | |||
86 | $innerHandler |
||
87 | ->expects($this->once()) |
||
88 | ->method('recover') |
||
89 | ->with($originalLocationId, $targetLocationId) |
||
90 | ->will($this->returnValue(null)); |
||
91 | |||
92 | $this->cacheMock |
||
93 | ->expects($this->once()) |
||
94 | ->method('invalidateTags') |
||
95 | ->with($tags); |
||
96 | |||
97 | $handler = $this->persistenceCacheHandler->$handlerMethodName(); |
||
98 | $handler->recover($originalLocationId, $targetLocationId); |
||
99 | } |
||
100 | |||
153 |