Conditions | 1 |
Paths | 1 |
Total Lines | 51 |
Code Lines | 37 |
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 |
||
101 | public function testTrashSubtree() |
||
102 | { |
||
103 | $locationId = 6; |
||
104 | $contentId = 42; |
||
105 | |||
106 | $tags = [ |
||
107 | 'content-' . $contentId, |
||
108 | 'content-fields-' . $contentId, |
||
109 | 'location-' . $locationId, |
||
110 | 'location-path-' . $locationId, |
||
111 | ]; |
||
112 | |||
113 | $handlerMethodName = $this->getHandlerMethodName(); |
||
114 | |||
115 | $this->loggerMock->expects($this->once())->method('logCall'); |
||
116 | |||
117 | $innerHandler = $this->createMock($this->getHandlerClassName()); |
||
118 | $contentHandlerMock = $this->createMock(ContentHandler::class); |
||
119 | $locationHandlerMock = $this->createMock(LocationHandler::class); |
||
120 | |||
121 | $locationHandlerMock |
||
122 | ->method('load') |
||
123 | ->will($this->returnValue(new Location(['id' => $locationId, 'contentId' => $contentId]))); |
||
124 | |||
125 | $this->persistenceHandlerMock |
||
126 | ->method('contentHandler') |
||
127 | ->will($this->returnValue($contentHandlerMock)); |
||
128 | |||
129 | $this->persistenceHandlerMock |
||
130 | ->method('locationHandler') |
||
131 | ->will($this->returnValue($locationHandlerMock)); |
||
132 | |||
133 | $this->persistenceHandlerMock |
||
134 | ->expects($this->once()) |
||
135 | ->method($handlerMethodName) |
||
136 | ->will($this->returnValue($innerHandler)); |
||
137 | |||
138 | $innerHandler |
||
139 | ->expects($this->once()) |
||
140 | ->method('trashSubtree') |
||
141 | ->with($locationId) |
||
142 | ->will($this->returnValue(null)); |
||
143 | |||
144 | $this->cacheMock |
||
145 | ->expects($this->once()) |
||
146 | ->method('invalidateTags') |
||
147 | ->with($tags); |
||
148 | |||
149 | $handler = $this->persistenceCacheHandler->$handlerMethodName(); |
||
150 | $handler->trashSubtree($locationId); |
||
151 | } |
||
152 | } |
||
153 |