| Conditions | 2 |
| Paths | 2 |
| 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 |
||
| 20 | public function generate(): Statement |
||
| 21 | { |
||
| 22 | $statementId = $this->generateStatementId('portfolio-comment'); |
||
| 23 | |||
| 24 | $userActor = new UserActor($this->comment->getAuthor()); |
||
| 25 | $statementResult = new Result(null, null, null, $this->comment->getContent()); |
||
| 26 | |||
| 27 | $context = $this->generateContext(); |
||
| 28 | |||
| 29 | $em = \Database::getManager(); |
||
| 30 | $commentAttachments = $em->getRepository(PortfolioAttachment::class)->findFromComment($this->comment); |
||
| 31 | |||
| 32 | $attachments = $this->generateAttachments( |
||
| 33 | $commentAttachments, |
||
| 34 | $this->comment->getAuthor() |
||
| 35 | ); |
||
| 36 | |||
| 37 | if ($this->parentComment) { |
||
| 38 | $repliedVerb = new RepliedVerb(); |
||
| 39 | |||
| 40 | $itemActivity = new PortfolioItemActivity($this->item); |
||
| 41 | $parentCommentActivity = new PortfolioCommentActivity($this->parentComment); |
||
| 42 | |||
| 43 | $contextActivities = $context |
||
| 44 | ->getContextActivities() |
||
| 45 | ->withAddedGroupingActivity($itemActivity->generate()); |
||
| 46 | |||
| 47 | return new Statement( |
||
| 48 | $statementId, |
||
| 49 | $userActor->generate(), |
||
| 50 | $repliedVerb->generate(), |
||
| 51 | $parentCommentActivity->generate(), |
||
| 52 | $statementResult, |
||
| 53 | null, |
||
| 54 | $this->comment->getDate(), |
||
| 55 | null, |
||
| 56 | $context->withContextActivities($contextActivities), |
||
| 57 | $attachments |
||
| 58 | ); |
||
| 59 | } else { |
||
| 60 | $itemShared = new PortfolioItemShared($this->item); |
||
| 61 | |||
| 62 | $commentedVerb = new CommentedVerb(); |
||
| 63 | |||
| 64 | return $itemShared->generate() |
||
| 65 | ->withId($statementId) |
||
| 66 | ->withActor($userActor->generate()) |
||
| 67 | ->withVerb($commentedVerb->generate()) |
||
| 68 | ->withStored($this->comment->getDate()) |
||
| 69 | ->withResult($statementResult) |
||
| 70 | ->withContext($context) |
||
| 71 | ->withAttachments($attachments); |
||
| 72 | } |
||
| 75 |