| Conditions | 6 |
| Paths | 7 |
| Total Lines | 67 |
| Code Lines | 35 |
| Lines | 0 |
| Ratio | 0 % |
| 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 |
||
| 52 | public function downloadMessageAsZipFile() { |
||
| 53 | if (!$this->store) { |
||
| 54 | return; |
||
| 55 | } |
||
| 56 | // Generate random ZIP file name at default temporary path of PHP |
||
| 57 | $randomZipName = tempnam(sys_get_temp_dir(), 'zip'); |
||
| 58 | |||
| 59 | // Create an open zip archive. |
||
| 60 | $zip = new ZipArchive(); |
||
| 61 | $result = $zip->open($randomZipName, ZipArchive::CREATE); |
||
| 62 | |||
| 63 | if ($result === true) { |
||
| 64 | for ($index = 0, $count = count($this->entryIds); $index < $count; ++$index) { |
||
| 65 | $this->message = mapi_msgstore_openentry($this->store, hex2bin((string) $this->entryIds[$index])); |
||
| 66 | |||
| 67 | // get message properties. |
||
| 68 | $messageProps = mapi_getprops($this->message, [PR_SUBJECT, PR_MESSAGE_CLASS]); |
||
| 69 | |||
| 70 | $stream = $this->getEmlStream($messageProps); |
||
| 71 | $stat = mapi_stream_stat($stream); |
||
| 72 | |||
| 73 | // Get the stream |
||
| 74 | $datastring = ''; |
||
| 75 | for ($i = 0; $i < $stat['cb']; $i += BLOCK_SIZE) { |
||
| 76 | $datastring .= mapi_stream_read($stream, BLOCK_SIZE); |
||
| 77 | // Need to discard the buffer contents to prevent memory |
||
| 78 | // exhaustion. |
||
| 79 | ob_flush(); |
||
| 80 | } |
||
| 81 | |||
| 82 | $filename = (!empty($messageProps[PR_SUBJECT])) ? $messageProps[PR_SUBJECT] : _('Untitled'); |
||
| 83 | $filename .= '.eml'; |
||
| 84 | |||
| 85 | $filename = $this->handleDuplicateFileNames($filename); |
||
| 86 | // Remove slashes to prevent unwanted directories to be created in the zip file. |
||
| 87 | $filename = str_replace('\\', '_', $filename); |
||
| 88 | $filename = str_replace('/', '_', $filename); |
||
| 89 | |||
| 90 | // Add file into zip by stream |
||
| 91 | $zip->addFromString($filename, $datastring); |
||
| 92 | } |
||
| 93 | } |
||
| 94 | else { |
||
| 95 | $zip->close(); |
||
| 96 | // Remove the zip file to avoid unnecessary disk-space consumption |
||
| 97 | unlink($randomZipName); |
||
| 98 | |||
| 99 | // Throw exception if ZIP is not created successfully |
||
| 100 | throw new ZarafaException(_("ZIP is not created successfully")); |
||
| 101 | } |
||
| 102 | |||
| 103 | $zip->close(); |
||
| 104 | |||
| 105 | // Set the headers |
||
| 106 | header('Pragma: public'); |
||
| 107 | header('Expires: 0'); // set expiration time |
||
| 108 | header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); |
||
| 109 | header('Content-Disposition: attachment; filename="' . addslashes(browserDependingHTTPHeaderEncode(_("Messages") . date(" d-m-Y") . ".zip")) . '"'); |
||
| 110 | header('Content-Transfer-Encoding: binary'); |
||
| 111 | header('Content-Type: application/zip'); |
||
| 112 | header('Content-Length: ' . filesize($randomZipName)); |
||
| 113 | |||
| 114 | // Send the actual response as ZIP file |
||
| 115 | readfile($randomZipName); |
||
| 116 | |||
| 117 | // Remove the zip file to avoid unnecessary disk-space consumption |
||
| 118 | unlink($randomZipName); |
||
| 119 | } |
||
| 168 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths