Code Duplication    Length = 98-102 lines in 2 locations

src/BenGorFile/File/Application/Command/Overwrite/OverwriteFileCommand.php 1 location

@@ 24-125 (lines=102) @@
21
 * @author Beñat Espiña <[email protected]>
22
 * @author Gorka Laucirica <[email protected]>
23
 */
24
class OverwriteFileCommand
25
{
26
    /**
27
     * The file id.
28
     *
29
     * @var string
30
     */
31
    private $id;
32
33
    /**
34
     * The file name.
35
     *
36
     * @var string
37
     */
38
    private $name;
39
40
    /**
41
     * The real content of file.
42
     *
43
     * @var mixed
44
     */
45
    private $uploadedFile;
46
47
    /**
48
     * The file mime type.
49
     *
50
     * @var string
51
     */
52
    private $mimeType;
53
54
    /**
55
     * Constructor.
56
     *
57
     * @param string $anId           The file id
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
     *
62
     * @throws \InvalidArgumentException           when the id or uploaded file given are null
63
     * @throws FileNameInvalidException            when the mime type given is null
64
     * @throws FileMimeTypeDoesNotSupportException when the name given is null
65
     */
66
    public function __construct($anId, $aName, $anUploadedFile, $aMimeType)
67
    {
68
        if (null === $anId) {
69
            throw new \InvalidArgumentException('The file id cannot be null');
70
        }
71
        if (null === $aName) {
72
            throw new FileNameInvalidException();
73
        }
74
        if (null === $anUploadedFile) {
75
            throw new \InvalidArgumentException('The file content cannot be null');
76
        }
77
        if (null === $aMimeType) {
78
            throw new FileMimeTypeDoesNotSupportException();
79
        }
80
        $this->id = $anId;
81
        $this->name = $aName;
82
        $this->uploadedFile = $anUploadedFile;
83
        $this->mimeType = $aMimeType;
84
    }
85
86
    /**
87
     * Gets the file id.
88
     *
89
     * @return string
90
     */
91
    public function id()
92
    {
93
        return $this->id;
94
    }
95
96
    /**
97
     * Gets the file name.
98
     *
99
     * @return string
100
     */
101
    public function name()
102
    {
103
        return $this->name;
104
    }
105
106
    /**
107
     * Gets the mime type.
108
     *
109
     * @return string
110
     */
111
    public function mimeType()
112
    {
113
        return $this->mimeType;
114
    }
115
116
    /**
117
     * Gets the real content of file.
118
     *
119
     * @return mixed
120
     */
121
    public function uploadedFile()
122
    {
123
        return $this->uploadedFile;
124
    }
125
}
126

src/BenGorFile/File/Application/Command/Upload/UploadFileCommand.php 1 location

@@ 25-122 (lines=98) @@
22
 * @author Beñat Espiña <[email protected]>
23
 * @author Gorka Laucirica <[email protected]>
24
 */
25
class UploadFileCommand
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