Passed
Push — master ( c7e98d...e0d6a2 )
by Anton
04:56 queued 01:50
created

Upload   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 6

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 6
dl 0
loc 36
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B handle() 0 31 5
1
<?php
2
3
namespace Modules\Filemanager\Handler {
4
5
	use Frames, Utils\Uploader, Ajax, Language, Request;
6
7
	class Upload extends Frames\Admin\Area\Authorized {
8
9
		# Handle request
10
11
		protected function handle() {
12
13
			if (!Request::isAjax()) return false;
14
15
			# Create response
16
17
			$ajax = Ajax::createResponse();
18
19
			# Get target directory
20
21
			$target_dir = ((Request::get('type') === 'image') ? 'data/images/' : 'data/');
22
23
			# Save uploaded file
24
25
			if (true === ($upload = (Uploader::save('upload', (DIR_UPLOADS . $target_dir))))) {
26
27
				$base_name = Uploader::baseName(); $url = (INSTALL_PATH . '/uploads/' . $target_dir . $base_name);
28
29
				$ajax->set('uploaded', 1)->set('fileName', $base_name)->set('url', $url);
30
31
			} else {
32
33
				$message = Language::get((false !== $upload) ? $upload : 'UPLOADER_ERROR_UNKNOWN');
0 ignored issues
show
Bug introduced by
It seems like false !== $upload ? $upl...UPLOADER_ERROR_UNKNOWN' can also be of type boolean; however, Language::get() does only seem to accept string, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
34
35
				$ajax->set('uploaded', 0)->setError(['message' => $message]);
36
			}
37
38
			# ------------------------
39
40
			return $ajax;
41
		}
42
	}
43
}
44