FineUploader   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 53
Duplicated Lines 16.98 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 73.91%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 4
dl 9
loc 53
ccs 17
cts 23
cp 0.7391
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A receive() 0 26 4
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 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($name);
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
        $totalparts = (int) $this->request->get('qqtotalparts', 1);
27 2
        $partindex = (int) $this->request->get('qqpartindex');
28 2
        $uuid = $this->request->get('qquuid');
29
30 2
        $chunkFile = $this->createChunkFile($originalName, $uuid);
31
32 2
        if ($completed === false) {
33 1
            $chunkFile->appendFile($file->getRealPath(), $partindex);
34
        }
35
36 2
        return $completed === true
37 1
            ? $chunkFile->createUploadedFile($totalparts)
38 1
            : $chunkFile->throwException([
39 1
                'success' => true,
40 2
                'uuid' => $uuid,
41
            ]);
42
    }
43
44
    /**
45
     * completedResponse.
46
     *
47
     * @param \Illuminate\Http\JsonResponse $response
48
     * @return \Illuminate\Http\JsonResponse
49
     */
50 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...
51
    {
52
        $data = $response->getData();
53
        $data->success = true;
54
        $data->uuid = $this->request->get('qquuid');
55
        $response->setData($data);
56
57
        return $response;
58
    }
59
}
60