Completed
Push — master ( 40400a...73c84a )
by recca
02:55
created

Plupload::receive()   B

Complexity

Conditions 3
Paths 3

Size

Total Lines 25
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 18
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
loc 25
ccs 18
cts 18
cp 1
rs 8.8571
c 0
b 0
f 0
cc 3
eloc 19
nc 3
nop 1
crap 3
1
<?php
2
3
namespace Recca0120\Upload;
4
5
use Illuminate\Http\JsonResponse;
6
7
class Plupload 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
        $uploadedFile = $this->request->file($name);
20 3
        $chunks = $this->request->get('chunks');
21 3
        if (empty($chunks) === true) {
22 1
            return $uploadedFile;
23
        }
24 2
        $chunk = $this->request->get('chunk');
25
26 2
        $originalName = $this->request->get('name');
27 2
        $start = $chunk * $this->request->header('content-length');
28 2
        $completed = $chunk >= $chunks - 1;
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($this->request->get('token'))
32 2
            ->setChunkPath($this->chunkPath())
33 2
            ->setStoragePath($this->storagePath())
34 2
            ->setName($originalName)
35 2
            ->setMimeType($uploadedFile->getMimeType())
36 2
            ->appendStream($uploadedFile->getPathname(), $start);
37
38
        return $completed === true
39 2
            ? $this->chunkFile->createUploadedFile()
40 2
            : $this->chunkFile->throwException();
41
    }
42
43
    /**
44
     * completedResponse.
45
     *
46
     * @param \Illuminate\Http\JsonResponse $response
47
     * @return \Illuminate\Http\JsonResponse
48
     */
49 1
    public function completedResponse(JsonResponse $response)
50
    {
51 1
        $data = $response->getData();
52 1
        $response->setData([
53 1
            'jsonrpc' => '2.0',
54 1
            'result' => $data,
55 1
        ]);
56
57 1
        return $response;
58
    }
59
}
60