Conditions | 11 |
Paths | 31 |
Total Lines | 49 |
Code Lines | 30 |
Lines | 0 |
Ratio | 0 % |
Changes | 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 declare(strict_types=1); |
||
79 | public function storeUpload(string $post_field, $response = null, $allowed_mimetypes = null) |
||
80 | { |
||
81 | //global $xoopsModuleConfig, $xoopsUser, $xoopsDB, $xoopsModule; |
||
82 | // require_once XHELP_CLASS_PATH . '/uploader.php'; |
||
83 | $config = Utility::getModuleConfig(); |
||
84 | |||
85 | $ticketid = $this->getVar('id'); |
||
86 | |||
87 | if (null === $allowed_mimetypes) { |
||
88 | /** @var \XoopsModules\Xhelp\MimetypeHandler $mimetypeHandler */ |
||
89 | $mimetypeHandler = $this->helper->getHandler('Mimetype'); |
||
90 | $allowed_mimetypes = $mimetypeHandler->checkMimeTypes($post_field); |
||
91 | if (!$allowed_mimetypes) { |
||
92 | return false; |
||
93 | } |
||
94 | } |
||
95 | |||
96 | $maxfilesize = $config['xhelp_uploadSize']; |
||
97 | $maxfilewidth = $config['xhelp_uploadWidth']; |
||
98 | $maxfileheight = $config['xhelp_uploadHeight']; |
||
99 | if (!\is_dir(XHELP_UPLOAD_PATH)) { |
||
100 | if (!\mkdir($concurrentDirectory = XHELP_UPLOAD_PATH, 0757) && !\is_dir($concurrentDirectory)) { |
||
101 | throw new \RuntimeException(\sprintf('Directory "%s" was not created', $concurrentDirectory)); |
||
102 | } |
||
103 | } |
||
104 | |||
105 | $uploader = new MediaUploader(XHELP_UPLOAD_PATH . '/', $allowed_mimetypes, $maxfilesize, $maxfilewidth, $maxfileheight); |
||
106 | if ($uploader->fetchMedia($post_field)) { |
||
107 | if (null === $response) { |
||
108 | $uploader->setTargetFileName($ticketid . '_' . $uploader->getMediaName()); |
||
109 | } else { |
||
110 | $uploader->setTargetFileName($ticketid . '_' . $response . '_' . $uploader->getMediaName()); |
||
111 | } |
||
112 | if ($uploader->upload()) { |
||
113 | $fileHandler = $this->helper->getHandler('File'); |
||
114 | $file = $fileHandler->create(); |
||
115 | $file->setVar('filename', $uploader->getSavedFileName()); |
||
116 | $file->setVar('ticketid', $ticketid); |
||
117 | $file->setVar('mimetype', $allowed_mimetypes); |
||
118 | $file->setVar('responseid', (null !== $response ? (int)$response : 0)); |
||
119 | |||
120 | if ($fileHandler->insert($file)) { |
||
121 | return $file; |
||
122 | } |
||
123 | |||
124 | return $uploader->getErrors(); |
||
125 | } |
||
126 | |||
127 | return $uploader->getErrors(); |
||
128 | } |
||
178 |