Issues (8)

src/File/UploadFileInfo.php (2 issues)

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
 *
13
 * @author      Josh Lockhart <[email protected]>
14
 * @copyright   2012 Josh Lockhart
15
 * @link        http://www.joshlockhart.com
16
 * @version     2.0.0
17
 *
18
 * Permission is hereby granted, free of charge, to any person obtaining a copy
19
 * of this software and associated documentation files (the "Software"), to deal
20
 * in the Software without restriction, including without limitation the rights
21
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
22
 * copies of the Software, and to permit persons to whom the Software is
23
 * furnished to do so, subject to the following conditions:
24
 *
25
 * The above copyright notice and this permission notice shall be included in all
26
 * copies or substantial portions of the Software.
27
 *
28
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
29
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
30
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
31
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
32
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
33
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
34
 * SOFTWARE.
35
 */
36
37
/**
38
 *  @file UploadFileInfo.php
39
 *
40
 *  The Upload File information class
41
 *
42
 *  @package    Platine\Upload\File
43
 *  @author Platine Developers Team
44
 *  @copyright  Copyright (c) 2020
45
 *  @license    http://opensource.org/licenses/MIT  MIT License
46
 *  @link   https://www.platine-php.com
47
 *  @version 1.0.0
48
 *  @filesource
49
 */
50
51
declare(strict_types=1);
52
53
namespace Platine\Upload\File;
54
55
/**
56
 * @class UploadFileInfo
57
 * @package Platine\Upload\File
58
 */
59
class UploadFileInfo
60
{
61
    /**
62
     * The full file name
63
     * @var string
64
     */
65
    protected string $fullName;
66
67
    /**
68
     * The file name (without extension)
69
     * @var string
70
     */
71
    protected string $name;
72
73
    /**
74
     * The file extension
75
     * @var string
76
     */
77
    protected string $extension;
78
79
    /**
80
     * The file mime type
81
     * @var string
82
     */
83
    protected string $mimeType = '';
84
85
    /**
86
     * The upload status
87
     * @var int
88
     */
89
    protected int $error;
90
91
    /**
92
     * The upload file size
93
     * @var int
94
     */
95
    protected int $size;
96
97
    /**
98
     * The file full path
99
     * @var string
100
     */
101
    protected string $path;
102
103
    /**
104
     * The file checksum
105
     * @var string
106
     */
107
    protected string $checksum;
108
109
    /**
110
     * Create new instance
111
     * @param string $path
112
     * @param string $mimeType
113
     * @param int $error
114
     * @param int $size
115
     * @param string $checksum
116
     */
117
    public function __construct(
118
        string $path,
119
        string $mimeType,
120
        int $error,
121
        int $size,
122
        string $checksum
123
    ) {
124
        $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...
125
        $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...
126
        $this->mimeType = $mimeType;
127
        $this->error = $error;
128
        $this->size = $size;
129
        $this->path = $path;
130
        $this->checksum = $checksum;
131
        $this->fullName = basename($path);
132
    }
133
134
    /**
135
     * Get the full name of the file
136
     * @return string
137
     */
138
    public function getFullName(): string
139
    {
140
        return $this->fullName;
141
    }
142
143
    /**
144
     * Get the checksum of the file
145
     * @return string
146
     */
147
    public function getChecksum(): string
148
    {
149
        return $this->checksum;
150
    }
151
152
    /**
153
     * Return the name of the file without extension
154
     * @return string
155
     */
156
    public function getName(): string
157
    {
158
        return $this->name;
159
    }
160
161
    /**
162
     * Return the extension of the file
163
     * @return string
164
     */
165
    public function getExtension(): string
166
    {
167
        return $this->extension;
168
    }
169
170
    /**
171
     * Return the mime type of the file
172
     * @return string
173
     */
174
    public function getMimeType(): string
175
    {
176
        return $this->mimeType;
177
    }
178
179
    /**
180
     * Return the file error code
181
     * @return int
182
     */
183
    public function getError(): int
184
    {
185
        return $this->error;
186
    }
187
188
    /**
189
     * Return the file size in byte
190
     * @return int
191
     */
192
    public function getSize(): int
193
    {
194
        return $this->size;
195
    }
196
197
    /**
198
     * Return the file full path
199
     * @return string
200
     */
201
    public function getPath(): string
202
    {
203
        return $this->path;
204
    }
205
}
206