Passed
Push — develop ( d0a329...633762 )
by nguereza
09:02
created

UploadFileInfo   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 127
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 22
dl 0
loc 127
rs 10
c 1
b 0
f 0
wmc 8

8 Methods

Rating   Name   Duplication   Size   Complexity  
A getPath() 0 3 1
A getFullName() 0 3 1
A getError() 0 3 1
A getSize() 0 3 1
A getExtension() 0 3 1
A __construct() 0 13 1
A getMimeType() 0 3 1
A getName() 0 3 1
1
<?php
2
3
/**
4
 * Platine Upload
5
 *
6
 * Platine Upload provides a flexible file uploads with extensible
7
 * validation and storage strategies.
8
 *
9
 * This content is released under the MIT License (MIT)
10
 *
11
 * Copyright (c) 2020 Platine Upload
12
 * Copyright (c) 2014 Adrian Miu
13
 *
14
 * Permission is hereby granted, free of charge, to any person obtaining a copy
15
 * of this software and associated documentation files (the "Software"), to deal
16
 * in the Software without restriction, including without limitation the rights
17
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
18
 * copies of the Software, and to permit persons to whom the Software is
19
 * furnished to do so, subject to the following conditions:
20
 *
21
 * The above copyright notice and this permission notice shall be included in all
22
 * copies or substantial portions of the Software.
23
 *
24
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
25
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
26
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
27
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
28
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
29
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30
 * SOFTWARE.
31
 */
32
33
/**
34
 *  @file UploadFileInfo.php
35
 *
36
 *  The Upload File information class
37
 *
38
 *  @package    Platine\Upload\File
39
 *  @author Platine Developers Team
40
 *  @copyright  Copyright (c) 2020
41
 *  @license    http://opensource.org/licenses/MIT  MIT License
42
 *  @link   http://www.iacademy.cf
43
 *  @version 1.0.0
44
 *  @filesource
45
 */
46
47
declare(strict_types=1);
48
49
namespace Platine\Upload\File;
50
51
/**
52
 * Class UploadFileInfo
53
 * @package Platine\Upload\File
54
 */
55
class UploadFileInfo
56
{
57
    /**
58
     * The full file name
59
     * @var string
60
     */
61
    protected string $fullName;
62
63
    /**
64
     * The file name (without extension)
65
     * @var string
66
     */
67
    protected string $name;
68
69
    /**
70
     * The file extension
71
     * @var string
72
     */
73
    protected string $extension;
74
75
    /**
76
     * The file mime type
77
     * @var string
78
     */
79
    protected string $mimeType = '';
80
81
    /**
82
     * The upload status
83
     * @var int
84
     */
85
    protected int $error;
86
87
    /**
88
     * The upload file size
89
     * @var int
90
     */
91
    protected int $size;
92
93
    /**
94
     * The file full path
95
     * @var string
96
     */
97
    protected string $path;
98
99
    /**
100
     * Create new instance
101
     * @param string $path
102
     * @param string $mimeType
103
     * @param int $error
104
     * @param int $size
105
     */
106
    public function __construct(
107
        string $path,
108
        string $mimeType,
109
        int $error,
110
        int $size
111
    ) {
112
        $this->name = pathinfo($path, PATHINFO_FILENAME);
0 ignored issues
show
Documentation Bug introduced by
It seems like pathinfo($path, Platine\...File\PATHINFO_FILENAME) can also be of type array. However, the property $name is declared as type string. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
113
        $this->extension = pathinfo($path, PATHINFO_EXTENSION);
0 ignored issues
show
Documentation Bug introduced by
It seems like pathinfo($path, Platine\...ile\PATHINFO_EXTENSION) can also be of type array. However, the property $extension is declared as type string. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
114
        $this->mimeType = $mimeType;
115
        $this->error = $error;
116
        $this->size = $size;
117
        $this->path = $path;
118
        $this->fullName = basename($path);
119
    }
120
121
    /**
122
     * Get the full name of the file
123
     * @return string
124
     */
125
    public function getFullName(): string
126
    {
127
        return $this->fullName;
128
    }
129
130
    /**
131
     * Return the name of the file without extension
132
     * @return string
133
     */
134
    public function getName(): string
135
    {
136
        return $this->name;
137
    }
138
139
    /**
140
     * Return the extension of the file
141
     * @return string
142
     */
143
    public function getExtension(): string
144
    {
145
        return $this->extension;
146
    }
147
148
    /**
149
     * Return the mime type of the file
150
     * @return string
151
     */
152
    public function getMimeType(): string
153
    {
154
        return $this->mimeType;
155
    }
156
157
    /**
158
     * Return the file error code
159
     * @return int
160
     */
161
    public function getError(): int
162
    {
163
        return $this->error;
164
    }
165
166
    /**
167
     * Return the file size in byte
168
     * @return int
169
     */
170
    public function getSize(): int
171
    {
172
        return $this->size;
173
    }
174
175
    /**
176
     * Return the file full path
177
     * @return string
178
     */
179
    public function getPath(): string
180
    {
181
        return $this->path;
182
    }
183
}
184