Conditions | 7 |
Paths | 36 |
Total Lines | 54 |
Code Lines | 40 |
Lines | 54 |
Ratio | 100 % |
Changes | 1 | ||
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 |
||
50 | View Code Duplication | public static function makeEnvelope(){ |
|
51 | $uid = md5(uniqid(time())); |
||
52 | $head = $body = []; |
||
53 | |||
54 | if ($this->from) $head[] = 'From: ' . $this->from; |
||
55 | if ($this->replyTo) $head[] = 'Reply-To: ' . $this->replyTo; |
||
56 | |||
57 | $head[] = 'MIME-Version: 1.0'; |
||
58 | $head[] = "Content-Type: multipart/mixed; boundary=\"".$uid."\""; |
||
59 | |||
60 | $body[] = "--$uid"; |
||
61 | $body[] = "Content-type: text/html; charset=UTF-8"; |
||
62 | $body[] = "Content-Transfer-Encoding: quoted-printable"; |
||
63 | $body[] = ''; |
||
64 | $body[] = quoted_printable_encode($this->message); |
||
65 | $body[] = ''; |
||
66 | |||
67 | |||
68 | foreach ($this->attachments as $file) { |
||
69 | if (is_string($file)) { |
||
70 | $name = basename($file); |
||
71 | $data = file_get_contents($file); |
||
72 | } else { |
||
73 | $name = $file['name']; |
||
74 | $data = $file['content']; |
||
75 | } |
||
76 | |||
77 | $body[] = "--$uid"; |
||
78 | $body[] = "Content-type: application/octet-stream; name=\"".$name."\""; |
||
79 | $body[] = "Content-Transfer-Encoding: base64"; |
||
80 | $body[] = "Content-Disposition: attachment; filename=\"".$name."\""; |
||
81 | $body[] = ''; |
||
82 | $body[] = chunk_split(base64_encode($data)); |
||
83 | $body[] = ''; |
||
84 | } |
||
85 | |||
86 | $body[] = "--$uid--"; |
||
87 | |||
88 | $success = true; |
||
89 | $head = implode("\r\n",$head); |
||
90 | $body = implode("\r\n",$body); |
||
91 | |||
92 | foreach ($this->recipients as $to) { |
||
93 | $current_success = mail( |
||
94 | $to, |
||
95 | $this->subject, |
||
96 | $body, |
||
97 | $head |
||
98 | ); |
||
99 | \Event::trigger('core.email.send', $to, $this->from, $this->subject, $body, $success); |
||
100 | $success = $success && $current_success; |
||
101 | } |
||
102 | return $success; |
||
103 | } |
||
104 | |||
159 |
This check looks for function or method calls that always return null and whose return value is assigned to a variable.
The method
getObject()
can return nothing but null, so it makes no sense to assign that value to a variable.The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.