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

Plupload   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 3
dl 0
loc 53
ccs 25
cts 25
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
B receive() 0 25 3
A completedResponse() 0 10 1
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