Conditions | 11 |
Paths | 512 |
Total Lines | 41 |
Code Lines | 25 |
Lines | 0 |
Ratio | 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 |
||
62 | public function xen_copy_files($dir, $row, $id_attach, $destination_path, $thumb = false) |
||
63 | { |
||
64 | // Extra details |
||
65 | list($ext, $basename, $mime_type) = attachment_type($row['filename']); |
||
66 | |||
67 | // Prep for the copy |
||
68 | $file = xen_attach_filename($row) . ($thumb ? '.' . $ext : '.data'); |
||
69 | $source = $dir . '/' . $file; |
||
70 | $file_hash = createAttachmentFileHash($file); |
||
71 | $destination = $destination_path . '/' . $id_attach . '_' . $file_hash . '.elk'; |
||
72 | $type = 0; |
||
73 | |||
74 | // Copy it over |
||
75 | copy_file($source, $destination); |
||
76 | |||
77 | // If its an image, then make sure it has legit width/height |
||
78 | if (!empty($ext)) |
||
79 | { |
||
80 | list ($width) = getimagesize($destination); |
||
81 | if (!empty($width)) |
||
82 | { |
||
83 | $type = ($thumb) ? 3 : 0; |
||
84 | } |
||
85 | } |
||
86 | |||
87 | // Prepare our insert |
||
88 | return array( |
||
89 | 'id_attach' => $id_attach, |
||
90 | 'id_thumb' => !$thumb && !empty($row['thumbnail_width']) ? ++$id_attach : 0, |
||
91 | 'size' => file_exists($destination) ? filesize($destination) : 0, |
||
92 | 'filename' => $basename . '.' . ($thumb ? $ext . '_thumb' : $ext), |
||
93 | 'file_hash' => $file_hash, |
||
94 | 'file_ext' => $ext, |
||
95 | 'mime_type' => $mime_type, |
||
96 | 'attachment_type' => $type, |
||
97 | 'id_msg' => $row['content_id'], |
||
98 | 'downloads' => $row['view_count'], |
||
99 | 'width' => $thumb ? $row['thumbnail_width'] : $row['width'], |
||
100 | 'height' => $thumb ? $row['thumbnail_height'] : $row['height'] |
||
101 | ); |
||
102 | } |
||
103 | |||
185 | } |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.