Completed
Push — master ( da99d4...871ace )
by Roberts
13s queued 10s
created

UploadController::errorResponse()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 7
nc 2
nop 0
dl 0
loc 11
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Arbory\Base\Http\Controllers\Admin;
4
5
use UniSharp\LaravelFilemanager\Controllers\UploadController as LfmUploadController;
6
7
/**
8
 * Class UploadController.
9
 */
10
class UploadController extends LfmUploadController
11
{
12
    /**
13
     * Upload files
14
     *
15
     * @param void
16
     * @return string
17
     */
18
    public function upload()
19
    {
20
        $response = parent::upload();
21
22
        return count($this->errors) > 0 ? $this->errorResponse() : $response;
0 ignored issues
show
Bug Best Practice introduced by
The expression return count($this->erro...rResponse() : $response also could return the type array which is incompatible with the documented return type string.
Loading history...
23
    }
24
25
    /**
26
     * Laravel File Manager and CKEditor integration is broken. In cases of unsuccessful uploads,
27
     * LFM returns error responses of unexpected format. This fixes that broken behaviour.
28
     *
29
     * @return array
30
     */
31
    protected function errorResponse()
32
    {
33
        if (request('responseType') === 'json') {
34
            return [
35
                "uploaded" => 0,
36
                "error" => [
37
                    "message" => implode(",\n", $this->errors)
38
                ]
39
            ];
40
        } else {
41
            return $this->errors;
42
        }
43
    }
44
}