UploadFileCommand   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 98
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 0
Metric Value
wmc 9
lcom 0
cbo 4
dl 98
loc 98
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
B __construct() 16 16 5
A id() 4 4 1
A name() 4 4 1
A mimeType() 4 4 1
A uploadedFile() 4 4 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
/*
4
 * This file is part of the BenGorFile package.
5
 *
6
 * (c) Beñat Espiña <[email protected]>
7
 * (c) Gorka Laucirica <[email protected]>
8
 *
9
 * For the full copyright and license information, please view the LICENSE
10
 * file that was distributed with this source code.
11
 */
12
13
namespace BenGorFile\File\Application\Command\Upload;
14
15
use BenGorFile\File\Domain\Model\FileMimeTypeDoesNotSupportException;
16
use BenGorFile\File\Domain\Model\FileNameInvalidException;
17
use Ramsey\Uuid\Uuid;
18
19
/**
20
 * Upload file command class.
21
 *
22
 * @author Beñat Espiña <[email protected]>
23
 * @author Gorka Laucirica <[email protected]>
24
 */
25 View Code Duplication
class UploadFileCommand
0 ignored issues
show
Duplication introduced by
This class 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...
26
{
27
    /**
28
     * The file id.
29
     *
30
     * @var string
31
     */
32
    private $id;
33
34
    /**
35
     * The file name.
36
     *
37
     * @var string
38
     */
39
    private $name;
40
41
    /**
42
     * The real content of file.
43
     *
44
     * @var mixed
45
     */
46
    private $uploadedFile;
47
48
    /**
49
     * The file mime type.
50
     *
51
     * @var string
52
     */
53
    private $mimeType;
54
55
    /**
56
     * Constructor.
57
     *
58
     * @param string      $aName          The file name
59
     * @param mixed       $anUploadedFile The real content of file
60
     * @param string      $aMimeType      The file mime type
61
     * @param string|null $anId           The file id
62
     *
63
     * @throws FileNameInvalidException            when the mime type given is null
64
     * @throws FileMimeTypeDoesNotSupportException when the name given is null
65
     */
66
    public function __construct($aName, $anUploadedFile, $aMimeType, $anId = null)
67
    {
68
        if (null === $aName) {
69
            throw new FileNameInvalidException();
70
        }
71
        if (null === $anUploadedFile) {
72
            throw new \InvalidArgumentException('The file content cannot be null');
73
        }
74
        if (null === $aMimeType) {
75
            throw new FileMimeTypeDoesNotSupportException();
76
        }
77
        $this->id = null === $anId ? Uuid::uuid4()->toString() : $anId;
78
        $this->name = $aName;
79
        $this->uploadedFile = $anUploadedFile;
80
        $this->mimeType = $aMimeType;
81
    }
82
83
    /**
84
     * Gets the file id.
85
     *
86
     * @return string
87
     */
88
    public function id()
89
    {
90
        return $this->id;
91
    }
92
93
    /**
94
     * Gets the file name.
95
     *
96
     * @return string
97
     */
98
    public function name()
99
    {
100
        return $this->name;
101
    }
102
103
    /**
104
     * Gets the mime type.
105
     *
106
     * @return string
107
     */
108
    public function mimeType()
109
    {
110
        return $this->mimeType;
111
    }
112
113
    /**
114
     * Gets the real content of file.
115
     *
116
     * @return mixed
117
     */
118
    public function uploadedFile()
119
    {
120
        return $this->uploadedFile;
121
    }
122
}
123