Conditions | 10 |
Paths | 66 |
Total Lines | 74 |
Code Lines | 29 |
Lines | 0 |
Ratio | 0 % |
Tests | 0 |
CRAP Score | 110 |
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 |
||
54 | protected function getMessage(Email $email): array |
||
55 | { |
||
56 | $from = $this->formatFrom($email); |
||
57 | $to = $this->formatToType('to', $email); |
||
58 | |||
59 | if (empty($to)) { |
||
60 | throw new \InvalidArgumentException('An email must have at least a single recipient'); |
||
61 | } |
||
62 | |||
63 | $message = [ |
||
64 | 'from' => $from, |
||
65 | 'to' => $to, |
||
66 | 'subject' => $email->getSubject() |
||
67 | ]; |
||
68 | |||
69 | /** |
||
70 | * HTML and text content |
||
71 | */ |
||
72 | $html = $email->getHtml(); |
||
73 | $text = $email->getText(); |
||
74 | |||
75 | if (empty($html) && empty($text)) { |
||
76 | throw new \InvalidArgumentException('A message body in HTML or text is missing'); |
||
77 | } |
||
78 | |||
79 | if (!empty($html)) { |
||
80 | $message['html'] = $html; |
||
81 | } |
||
82 | |||
83 | if (!empty($text)) { |
||
84 | $message['text'] = $text; |
||
85 | } |
||
86 | |||
87 | /** |
||
88 | * CC |
||
89 | */ |
||
90 | $cc = $this->formatToType('cc', $email); |
||
91 | |||
92 | if (!empty($cc)) { |
||
93 | $message['cc'] = $cc; |
||
94 | } |
||
95 | |||
96 | /** |
||
97 | * BCC |
||
98 | */ |
||
99 | $bcc = $this->formatToType('bcc', $email); |
||
100 | |||
101 | if (!empty($bcc)) { |
||
102 | $message['bcc'] = $bcc; |
||
103 | } |
||
104 | |||
105 | /** |
||
106 | * Headers |
||
107 | */ |
||
108 | foreach ($email->getHeaders() as $header => $value) { |
||
109 | $message["h:$header"] = $value; |
||
110 | } |
||
111 | |||
112 | /** |
||
113 | * Tag |
||
114 | */ |
||
115 | $tag = $email->getTag(); |
||
116 | |||
117 | if (!empty($tag)) { |
||
118 | $message['o:tag'] = $tag; |
||
119 | } |
||
120 | |||
121 | // @todo Handle campaign ('o:campaign') |
||
122 | |||
123 | // @todo Handle attachment ('attachment') |
||
124 | // @todo Handle inline ('o:inline') |
||
125 | |||
126 | return $message; |
||
127 | } |
||
128 | |||
168 |