Completed
Push — master ( 375fd2...2f75f2 )
by recca
01:54
created

FineUploader::completedResponse()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 9
ccs 0
cts 6
cp 0
rs 9.6666
cc 1
eloc 6
nc 1
nop 1
crap 2
1
<?php
2
3
namespace Recca0120\Upload;
4
5
use Illuminate\Http\JsonResponse;
6
7
class FineUploader extends Api
8
{
9
    /**
10
     * receive.
11
     *
12
     * @param string $name
13
     * @return \Symfony\Component\HttpFoundation\File\UploadedFile
14
     *
15
     * @throws \Recca0120\Upload\Exceptions\ChunkedResponseException
16
     */
17 3
    public function receive($name)
18
    {
19 3
        $file = $this->request->file('qqfile');
20 3
        if ($this->request->has('qqtotalparts') === false) {
21 1
            return $file;
22
        }
23
24 2
        $completed = is_null($file) === true;
25 2
        $originalName = $this->request->get('qqfilename');
26 2
        $qqtotalparts = (int) $this->request->get('qqtotalparts', 1);
27 2
        $qqpartindex = (int) $this->request->get('qqpartindex');
28 2
        $uuid = $this->request->get('qquuid');
29
30 2
        $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...
31 2
            ->setToken($uuid)
32 2
            ->setChunkPath($this->chunkPath())
33 2
            ->setStoragePath($this->storagePath())
34 2
            ->setName($originalName);
35
36 2
        if ($completed === false) {
37 1
            $this->chunkFile->appendStream($file->getRealPath(), 0, $qqpartindex);
38 1
        }
39
40
        return $completed === true
41 2
            ? $this->chunkFile->createUploadedFile($qqtotalparts)
42 2
            : $this->chunkFile->throwException([
43 1
                'success' => true,
44 1
                'uuid' => $uuid,
45 2
            ]);
46
    }
47
48
    /**
49
     * completedResponse.
50
     *
51
     * @param \Illuminate\Http\JsonResponse $response
52
     * @return \Illuminate\Http\JsonResponse
53
     */
54
    public function completedResponse(JsonResponse $response)
55
    {
56
        $data = $response->getData();
57
        $data->success = true;
58
        $data->uuid = $this->request->get('qquuid');
59
        $response->setData($data);
60
61
        return $response;
62
    }
63
}
64