Conditions | 7 |
Paths | 17 |
Total Lines | 51 |
Code Lines | 22 |
Lines | 0 |
Ratio | 0 % |
Changes | 5 | ||
Bugs | 0 | Features | 2 |
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 namespace Camelcased\Postmark\Inbound\Parse; |
||
39 | public function parse() |
||
40 | { |
||
41 | if ($this->inbound == []) |
||
42 | { |
||
43 | // Well that was short lived. |
||
44 | return []; |
||
45 | } |
||
46 | |||
47 | // Set the Body field based on whether it is HTMl or good old fashioned plain text |
||
48 | if (!$this->htmlBody()) |
||
49 | { |
||
50 | $this->output['body'] = $this->inbound["TextBody"]; |
||
51 | } else { |
||
52 | $this->output['body'] = $this->inbound["HtmlBody"]; |
||
53 | } |
||
54 | |||
55 | // Easy stuff to parse. Self explainatory. |
||
56 | $this->output['subject'] = $this->inbound["Subject"]; |
||
57 | $this->output['to'] = $this->inbound["To"]; |
||
58 | $this->output['replyTo'] = $this->replyTo(); |
||
59 | $this->output['from'] = $this->inbound["From"]; |
||
60 | |||
61 | // Set cc field if the email has any CC's set |
||
62 | if ($this->has('Cc')) |
||
63 | { |
||
64 | $this->output['cc'] = $this->carbon('Cc'); |
||
65 | } |
||
66 | |||
67 | // Set bcc field if the email has any BCC's set |
||
68 | if ($this->has('Bcc')) |
||
69 | { |
||
70 | $this->output['bcc'] = $this->carbon('Bcc'); |
||
71 | } |
||
72 | |||
73 | // Does the email have any attachments |
||
74 | if ($this->has('Attachments')) |
||
75 | { |
||
76 | $this->output['Attachments'] = []; |
||
77 | $i = 0; |
||
78 | |||
79 | // Loop through each of the attachments and convert it to an array for later use |
||
80 | foreach($this->inbound["Attachments"] as $attachment) |
||
81 | { |
||
82 | $this->output['Attachments'][$i] = ["Name" => $attachment["Name"], "Content" => $attachment["Content"], "MIME" => $attachment["ContentType"]]; |
||
83 | $i++; |
||
84 | } |
||
85 | } |
||
86 | |||
87 | // Return the parsed email |
||
88 | return $this->output; |
||
89 | } |
||
90 | |||
190 |