Upload   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 38
rs 10
c 1
b 0
f 0
wmc 5
lcom 0
cbo 6

1 Method

Rating   Name   Duplication   Size   Complexity  
B handle() 0 29 5
1
<?php
2
3
/**
4
 * @package Cadmium\System\Modules\Filemanager
5
 * @author Anton Romanov
6
 * @copyright Copyright (c) 2015-2017, Anton Romanov
7
 * @link http://cadmium-cms.com
8
 */
9
10
namespace Modules\Filemanager\Handler {
11
12
	use Frames, Utils\Uploader, Ajax, Language, Request;
13
14
	class Upload extends Frames\Admin\Area\Panel {
15
16
		/**
17
		 * Handle the request
18
		 *
19
		 * @return Ajax\Response|false : an ajax response if the ajax param was set to true, otherwise false
20
		 */
21
22
		protected function handle(bool $ajax = false) {
23
24
			if (!$ajax) return false;
25
26
			# Create response
27
28
			$ajax = Ajax::createResponse();
29
30
			# Get target directory
31
32
			$target_dir = ((Request::get('type') === 'image') ? 'data/images/' : 'data/');
33
34
			# Save uploaded file
35
36
			if (true === ($upload = (Uploader::save('upload', (DIR_UPLOADS . $target_dir))))) {
37
38
				$name = Uploader::getBasename(); $url = (INSTALL_PATH . '/uploads/' . $target_dir . $name);
39
40
				$ajax->set('name', $name)->set('url', $url);
41
42
			} else {
43
44
				$ajax->setError(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...
45
			}
46
47
			# ------------------------
48
49
			return $ajax;
50
		}
51
	}
52
}
53