x Sorry, these patches are not available anymore due to data migration. Please run a fresh inspection.
Completed
Push — master ( cc89ae...0c9118 )
by recca
04:22
created

Dropzone::completedResponse()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 6

Duplication

Lines 9
Ratio 100 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 9
loc 9
ccs 0
cts 6
cp 0
rs 9.6666
c 0
b 0
f 0
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 Dropzone extends FineUploader
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($name);
20 3
        if ($this->request->has('dztotalchunkcount') === false) {
21 1
            return $file;
22
        }
23
24 2
        $originalName = $file->getClientOriginalName();
25 2
        $totalparts = (int) $this->request->get('dztotalchunkcount', 1);
26 2
        $partindex = (int) $this->request->get('dzchunkindex');
27 2
        $uuid = $this->request->get('dzuuid');
28
29 2
        $this->chunkFile
30 2
            ->setToken($uuid)
31 2
            ->setChunkPath($this->chunkPath())
32 2
            ->setStoragePath($this->storagePath())
33 2
            ->setName($originalName)
34 2
            ->appendFile($file->getRealPath(), $partindex);
35
36 2
        $completed = $totalparts - 1 === $partindex;
37
38 2
        return $completed === true
39 1
            ? $this->chunkFile->createUploadedFile($totalparts)
40 1
            : $this->chunkFile->throwException([
41 1
                'success' => true,
42 2
                'uuid' => $uuid,
43
            ]);
44
    }
45
46
    /**
47
     * completedResponse.
48
     *
49
     * @param \Illuminate\Http\JsonResponse $response
50
     * @return \Illuminate\Http\JsonResponse
51
     */
52 View Code Duplication
    public function completedResponse(JsonResponse $response)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
53
    {
54
        $data = $response->getData();
55
        $data->success = true;
56
        $data->uuid = $this->request->get('dzuuid');
57
        $response->setData($data);
58
59
        return $response;
60
    }
61
}
62