Dropzone   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 51
Duplicated Lines 17.65 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 72.72%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 4
dl 9
loc 51
ccs 16
cts 22
cp 0.7272
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A receive() 0 24 3
A completedResponse() 9 9 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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
        $chunkFile = $this->createChunkFile($originalName, $uuid);
30 2
        $chunkFile->appendFile($file->getRealPath(), $partindex);
31
32 2
        $completed = $totalparts - 1 === $partindex;
33
34 2
        return $completed === true
35 1
            ? $chunkFile->createUploadedFile($totalparts)
36 1
            : $chunkFile->throwException([
37 1
                'success' => true,
38 2
                'uuid' => $uuid,
39
            ]);
40
    }
41
42
    /**
43
     * completedResponse.
44
     *
45
     * @param \Illuminate\Http\JsonResponse $response
46
     * @return \Illuminate\Http\JsonResponse
47
     */
48 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...
49
    {
50
        $data = $response->getData();
51
        $data->success = true;
52
        $data->uuid = $this->request->get('dzuuid');
53
        $response->setData($data);
54
55
        return $response;
56
    }
57
}
58