Conditions | 1 |
Paths | 1 |
Total Lines | 219 |
Code Lines | 171 |
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 |
||
120 | public function successServiceProvider() |
||
121 | { |
||
122 | $authorUuid = Uuid::uuid4()->toString(); |
||
123 | $postUuid = Uuid::uuid4()->toString(); |
||
124 | $tagUuid = Uuid::uuid4()->toString(); |
||
125 | $trailUuid = Uuid::uuid4()->toString(); |
||
126 | |||
127 | $author = new Author('Davis', '[email protected]', 'Some string', $authorUuid, new DateTime()); |
||
128 | $post = new Post('A Post', 'Lorem ipsum', $author, $postUuid, [], null); |
||
129 | $tag = new Tag('A tag', $tagUuid); |
||
130 | $trail = new Trail('A trail', 'An amazing trail', $trailUuid, [$post]); |
||
131 | $filters = []; |
||
132 | |||
133 | return [ |
||
134 | [ |
||
135 | CreateAuthor::class, |
||
136 | 'save', |
||
137 | $authorUuid, |
||
138 | $this->getMockForAbstractClass(AbstractAuthorRepository::class), |
||
139 | $author, |
||
140 | $this->createMock(LoggerInterface::class), |
||
141 | $authorUuid, |
||
142 | 'Create author service', |
||
143 | ], |
||
144 | [ |
||
145 | EditAuthor::class, |
||
146 | 'save', |
||
147 | $authorUuid, |
||
148 | $this->getMockForAbstractClass(AbstractAuthorRepository::class), |
||
149 | $author, |
||
150 | $this->createMock(LoggerInterface::class), |
||
151 | $authorUuid, |
||
152 | 'Edit author service', |
||
153 | ], |
||
154 | [ |
||
155 | DeleteAuthor::class, |
||
156 | 'delete', |
||
157 | true, |
||
158 | $this->getMockForAbstractClass(AbstractAuthorRepository::class), |
||
159 | $author, |
||
160 | $this->createMock(LoggerInterface::class), |
||
161 | true, |
||
162 | 'Delete author service', |
||
163 | ], |
||
164 | [ |
||
165 | GetAuthor::class, |
||
166 | 'get', |
||
167 | $author, |
||
168 | $this->getMockForAbstractClass(AbstractAuthorRepository::class), |
||
169 | $authorUuid, |
||
170 | $this->createMock(LoggerInterface::class), |
||
171 | $author, |
||
172 | 'Get author service', |
||
173 | ], |
||
174 | [ |
||
175 | ListAuthors::class, |
||
176 | 'getList', |
||
177 | [$author], |
||
178 | $this->getMockForAbstractClass(AbstractAuthorRepository::class), |
||
179 | $filters, |
||
180 | $this->createMock(LoggerInterface::class), |
||
181 | [$author], |
||
182 | 'List authors service', |
||
183 | ], |
||
184 | |||
185 | [ |
||
186 | CreatePost::class, |
||
187 | 'save', |
||
188 | $postUuid, |
||
189 | $this->getMockForAbstractClass(AbstractPostRepository::class), |
||
190 | $post, |
||
191 | $this->createMock(LoggerInterface::class), |
||
192 | $postUuid, |
||
193 | 'Create post service', |
||
194 | ], |
||
195 | [ |
||
196 | EditPost::class, |
||
197 | 'save', |
||
198 | $postUuid, |
||
199 | $this->getMockForAbstractClass(AbstractPostRepository::class), |
||
200 | $post, |
||
201 | $this->createMock(LoggerInterface::class), |
||
202 | $postUuid, |
||
203 | 'Edit post service', |
||
204 | ], |
||
205 | [ |
||
206 | DeletePost::class, |
||
207 | 'delete', |
||
208 | true, |
||
209 | $this->getMockForAbstractClass(AbstractPostRepository::class), |
||
210 | $post, |
||
211 | $this->createMock(LoggerInterface::class), |
||
212 | true, |
||
213 | 'Delete post service', |
||
214 | ], |
||
215 | [ |
||
216 | GetPost::class, |
||
217 | 'get', |
||
218 | $post, |
||
219 | $this->getMockForAbstractClass(AbstractPostRepository::class), |
||
220 | $postUuid, |
||
221 | $this->createMock(LoggerInterface::class), |
||
222 | $post, |
||
223 | 'Get post service', |
||
224 | ], |
||
225 | [ |
||
226 | ListPosts::class, |
||
227 | 'getList', |
||
228 | [$post], |
||
229 | $this->getMockForAbstractClass(AbstractPostRepository::class), |
||
230 | $filters, |
||
231 | $this->createMock(LoggerInterface::class), |
||
232 | [$post], |
||
233 | 'List posts service', |
||
234 | ], |
||
235 | |||
236 | [ |
||
237 | CreateTag::class, |
||
238 | 'save', |
||
239 | $tagUuid, |
||
240 | $this->getMockForAbstractClass(AbstractTagRepository::class), |
||
241 | $tag, |
||
242 | $this->createMock(LoggerInterface::class), |
||
243 | $tagUuid, |
||
244 | 'Create tag service', |
||
245 | ], |
||
246 | [ |
||
247 | EditTag::class, |
||
248 | 'save', |
||
249 | $tagUuid, |
||
250 | $this->getMockForAbstractClass(AbstractTagRepository::class), |
||
251 | $tag, |
||
252 | $this->createMock(LoggerInterface::class), |
||
253 | $tagUuid, |
||
254 | 'Edit tag service', |
||
255 | ], |
||
256 | [ |
||
257 | DeleteTag::class, |
||
258 | 'delete', |
||
259 | true, |
||
260 | $this->getMockForAbstractClass(AbstractTagRepository::class), |
||
261 | $tag, |
||
262 | $this->createMock(LoggerInterface::class), |
||
263 | true, |
||
264 | 'Delete tag service', |
||
265 | ], |
||
266 | [ |
||
267 | GetTag::class, |
||
268 | 'get', |
||
269 | $tag, |
||
270 | $this->getMockForAbstractClass(AbstractTagRepository::class), |
||
271 | $tagUuid, |
||
272 | $this->createMock(LoggerInterface::class), |
||
273 | $tag, |
||
274 | 'Get tag service', |
||
275 | ], |
||
276 | [ |
||
277 | ListTags::class, |
||
278 | 'getList', |
||
279 | [$tag], |
||
280 | $this->getMockForAbstractClass(AbstractTagRepository::class), |
||
281 | $filters, |
||
282 | $this->createMock(LoggerInterface::class), |
||
283 | [$tag], |
||
284 | 'List tags service', |
||
285 | ], |
||
286 | |||
287 | [ |
||
288 | CreateTrail::class, |
||
289 | 'save', |
||
290 | $trailUuid, |
||
291 | $this->getMockForAbstractClass(AbstractTrailRepository::class), |
||
292 | $trail, |
||
293 | $this->createMock(LoggerInterface::class), |
||
294 | $trailUuid, |
||
295 | 'Create trail service', |
||
296 | ], |
||
297 | [ |
||
298 | EditTrail::class, |
||
299 | 'save', |
||
300 | $trailUuid, |
||
301 | $this->getMockForAbstractClass(AbstractTrailRepository::class), |
||
302 | $trail, |
||
303 | $this->createMock(LoggerInterface::class), |
||
304 | $trailUuid, |
||
305 | 'Edit trail service', |
||
306 | ], |
||
307 | [ |
||
308 | DeleteTrail::class, |
||
309 | 'delete', |
||
310 | true, |
||
311 | $this->getMockForAbstractClass(AbstractTrailRepository::class), |
||
312 | $trail, |
||
313 | $this->createMock(LoggerInterface::class), |
||
314 | true, |
||
315 | 'Delete trail service', |
||
316 | ], |
||
317 | [ |
||
318 | GetTrail::class, |
||
319 | 'get', |
||
320 | $trail, |
||
321 | $this->getMockForAbstractClass(AbstractTrailRepository::class), |
||
322 | $trailUuid, |
||
323 | $this->createMock(LoggerInterface::class), |
||
324 | $trail, |
||
325 | 'Get trail service', |
||
326 | ], |
||
327 | [ |
||
328 | ListTrails::class, |
||
329 | 'getList', |
||
330 | [$trail], |
||
331 | $this->getMockForAbstractClass(AbstractTrailRepository::class), |
||
332 | $filters, |
||
333 | $this->createMock(LoggerInterface::class), |
||
334 | [$trail], |
||
335 | 'List trails service', |
||
336 | ], |
||
337 | ]; |
||
338 | } |
||
339 | |||
680 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.