| Conditions | 5 |
| Paths | 4 |
| Total Lines | 25 |
| Code Lines | 20 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 0 |
| CRAP Score | 30 |
| Changes | 0 | ||
| 1 | <?php |
||
| 16 | protected function save(string $contents, string $name): string |
||
| 17 | { |
||
| 18 | $uploadsDir = wp_upload_dir(); |
||
| 19 | $baseDir = trailingslashit($uploadsDir['basedir']); |
||
| 20 | $baseUrl = trailingslashit($uploadsDir['baseurl']); |
||
| 21 | $pathDir = trailingslashit(glsr()->id).trailingslashit('avatars'); |
||
| 22 | $filename = sprintf('%s.svg', $name ?: 'blank'); |
||
| 23 | $filepath = $baseDir.$pathDir.$filename; |
||
| 24 | if (!file_exists($filepath)) { |
||
| 25 | wp_mkdir_p($baseDir.$pathDir); |
||
| 26 | $fp = @fopen($filepath, 'wb'); |
||
| 27 | if (false === $fp) { |
||
| 28 | return ''; |
||
| 29 | } |
||
| 30 | mbstring_binary_safe_encoding(); |
||
| 31 | $dataLength = strlen($contents); |
||
| 32 | $bytesWritten = fwrite($fp, $contents); |
||
| 33 | reset_mbstring_encoding(); |
||
| 34 | fclose($fp); |
||
| 35 | if ($dataLength !== $bytesWritten) { |
||
| 36 | return ''; |
||
| 37 | } |
||
| 38 | chmod($filepath, fileperms(ABSPATH.'index.php') & 0777 | 0644); |
||
| 39 | } |
||
| 40 | return set_url_scheme($baseUrl.$pathDir.$filename); |
||
| 41 | } |
||
| 43 |