Completed
Push — master ( 2c9ac3...375fd2 )
by recca
01:55
created

FineUploader::receive()   B

Complexity

Conditions 4
Paths 5

Size

Total Lines 30
Code Lines 20

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 20

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 30
ccs 0
cts 21
cp 0
rs 8.5806
cc 4
eloc 20
nc 5
nop 1
crap 20
1
<?php
2
3
namespace Recca0120\Upload;
4
5
use Illuminate\Support\Arr;
6
use Illuminate\Http\JsonResponse;
7
8
class FineUploader extends Api
9
{
10
    /**
11
     * receive.
12
     *
13
     * @param string $name
14
     * @return \Symfony\Component\HttpFoundation\File\UploadedFile
15
     *
16
     * @throws \Recca0120\Upload\Exceptions\ChunkedResponseException
17
     */
18
    public function receive($name)
19
    {
20
        if ($this->request->has('qqtotalparts') === false) {
21
            return $this->request->file('qqfile');
22
        }
23
24
        $originalName = $this->request->get('qqfilename');
25
        $qqtotalparts = (int) $this->request->get('qqtotalparts', 1);
26
        $qqpartindex = (int) $this->request->get('qqpartindex');
27
        $file = $this->request->file('qqfile');
28
29
        $completed = is_null($file);
30
31
        $this->chunkFile
0 ignored issues
show
Bug introduced by
The property chunkFile does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
32
            ->setToken($this->request->get('qquuid'))
33
            ->setChunkPath($this->chunkPath())
34
            ->setStoragePath($this->storagePath())
35
            ->setName($originalName);
36
37
        if ($completed === false) {
38
            $this->chunkFile->appendStream($file->getRealPath(), 0, $qqpartindex);
39
        }
40
41
        return $completed === true
42
            ? $this->chunkFile->createUploadedFile($qqtotalparts)
43
            : $this->chunkFile->throwException(json_encode([
44
                'success' => true,
45
                'uuid' => $this->request->get('qquuid'),
46
            ]));
47
    }
48
49
    /**
50
     * completedResponse.
51
     *
52
     * @param \Illuminate\Http\JsonResponse $response
53
     * @return \Illuminate\Http\JsonResponse
54
     */
55
    public function completedResponse(JsonResponse $response)
56
    {
57
        $data = $response->getData();
58
        $data->success = true;
59
        $data->uuid = $this->request->get('qquuid');
60
        $response->setData($data);
61
62
        return $response;
63
    }
64
}
65