UploadFileCommand::__construct()   B
last analyzed

Complexity

Conditions 5
Paths 5

Size

Total Lines 16
Code Lines 11

Duplication

Lines 16
Ratio 100 %

Importance

Changes 0
Metric Value
dl 16
loc 16
rs 8.8571
c 0
b 0
f 0
cc 5
eloc 11
nc 5
nop 4
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