| Conditions | 10 |
| Paths | 216 |
| Total Lines | 52 |
| Code Lines | 35 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 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 |
||
| 17 | public function create(MessageInterface $message): Email |
||
| 18 | { |
||
| 19 | $email = (new Email()) |
||
| 20 | ->from(...$this->convertStringsToAddresses($message->getFrom())) |
||
| 21 | ->to(...$this->convertStringsToAddresses($message->getTo())) |
||
| 22 | ->replyTo(...$this->convertStringsToAddresses($message->getReplyTo())) |
||
| 23 | ->cc(...$this->convertStringsToAddresses($message->getCc())) |
||
| 24 | ->bcc(...$this->convertStringsToAddresses($message->getBcc())) |
||
| 25 | ->subject($message->getSubject()) |
||
| 26 | ->priority($message->getPriority()) |
||
| 27 | ->text($message->getTextBody(), $message->getCharset()) |
||
| 28 | ->html($message->getHtmlBody(), $message->getCharset()); |
||
| 29 | |||
| 30 | $returnPath = $message->getReturnPath(); |
||
| 31 | if ($returnPath !== '') { |
||
| 32 | $email->returnPath($returnPath); |
||
| 33 | } |
||
| 34 | |||
| 35 | $sender = $message->getSender(); |
||
| 36 | if ($sender !== '') { |
||
| 37 | $email->sender($sender); |
||
| 38 | } |
||
| 39 | |||
| 40 | $date = $message->getDate(); |
||
| 41 | if ($date !== null) { |
||
| 42 | $email->date($date); |
||
| 43 | } |
||
| 44 | |||
| 45 | $emailHeaders = $email->getHeaders(); |
||
| 46 | foreach ($message->getHeaders() as $name => $values) { |
||
|
|
|||
| 47 | foreach ($values as $value) { |
||
| 48 | match ($name) { |
||
| 49 | 'Date' => $emailHeaders->addDateHeader($name, new DateTimeImmutable($value)), |
||
| 50 | 'Message-ID' => $emailHeaders->addIdHeader($name, $value), |
||
| 51 | default => $emailHeaders->addTextHeader($name, $value), |
||
| 52 | }; |
||
| 53 | } |
||
| 54 | } |
||
| 55 | |||
| 56 | foreach ($message->getAttachments() as $file) { |
||
| 57 | $file->path() === null |
||
| 58 | ? $email->attach((string) $file->content(), $file->name(), $file->contentType()) |
||
| 59 | : $email->attachFromPath($file->path(), $file->name(), $file->contentType()); |
||
| 60 | } |
||
| 61 | |||
| 62 | foreach ($message->getEmbeddedFiles() as $file) { |
||
| 63 | $file->path() === null |
||
| 64 | ? $email->embed((string) $file->content(), $file->name(), $file->contentType()) |
||
| 65 | : $email->embedFromPath($file->path(), $file->name(), $file->contentType()); |
||
| 66 | } |
||
| 67 | |||
| 68 | return $email; |
||
| 69 | } |
||
| 117 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.