Conditions | 5 |
Paths | 5 |
Total Lines | 31 |
Code Lines | 11 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | <?php |
||
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'); |
||
|
|||
34 | |||
35 | $ajax->set('uploaded', 0)->setError(['message' => $message]); |
||
36 | } |
||
37 | |||
38 | # ------------------------ |
||
39 | |||
40 | return $ajax; |
||
41 | } |
||
42 | } |
||
44 |
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:
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.