| 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 |  |  |      * The file name on user machine | 
            
                                                                        
                            
            
                                    
            
            
                | 111 |  |  |      * @var string | 
            
                                                                        
                            
            
                                    
            
            
                | 112 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 113 |  |  |     protected string $clientName = ''; | 
            
                                                                        
                            
            
                                    
            
            
                | 114 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 115 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 116 |  |  |      * Create new instance | 
            
                                                                        
                            
            
                                    
            
            
                | 117 |  |  |      * @param string $path | 
            
                                                                        
                            
            
                                    
            
            
                | 118 |  |  |      * @param string $mimeType | 
            
                                                                        
                            
            
                                    
            
            
                | 119 |  |  |      * @param int $error | 
            
                                                                        
                            
            
                                    
            
            
                | 120 |  |  |      * @param int $size | 
            
                                                                        
                            
            
                                    
            
            
                | 121 |  |  |      * @param string $checksum | 
            
                                                                        
                            
            
                                    
            
            
                | 122 |  |  |      * @param string $clientName | 
            
                                                                        
                            
            
                                    
            
            
                | 123 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 124 |  |  |     public function __construct( | 
            
                                                                        
                            
            
                                    
            
            
                | 125 |  |  |         string $path, | 
            
                                                                        
                            
            
                                    
            
            
                | 126 |  |  |         string $mimeType, | 
            
                                                                        
                            
            
                                    
            
            
                | 127 |  |  |         int $error, | 
            
                                                                        
                            
            
                                    
            
            
                | 128 |  |  |         int $size, | 
            
                                                                        
                            
            
                                    
            
            
                | 129 |  |  |         string $checksum, | 
            
                                                                        
                            
            
                                    
            
            
                | 130 |  |  |         string $clientName | 
            
                                                                        
                            
            
                                    
            
            
                | 131 |  |  |     ) { | 
            
                                                                        
                            
            
                                    
            
            
                | 132 |  |  |         $this->name = pathinfo($path, PATHINFO_FILENAME); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 133 |  |  |         $this->extension = pathinfo($path, PATHINFO_EXTENSION); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 134 |  |  |         $this->mimeType = $mimeType; | 
            
                                                                        
                            
            
                                    
            
            
                | 135 |  |  |         $this->error = $error; | 
            
                                                                        
                            
            
                                    
            
            
                | 136 |  |  |         $this->size = $size; | 
            
                                                                        
                            
            
                                    
            
            
                | 137 |  |  |         $this->path = $path; | 
            
                                                                        
                            
            
                                    
            
            
                | 138 |  |  |         $this->checksum = $checksum; | 
            
                                                                        
                            
            
                                    
            
            
                | 139 |  |  |         $this->clientName = $clientName; | 
            
                                                                        
                            
            
                                    
            
            
                | 140 |  |  |         $this->fullName = basename($path); | 
            
                                                                        
                            
            
                                    
            
            
                | 141 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 142 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 143 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 144 |  |  |      * Get the full name of the file | 
            
                                                                        
                            
            
                                    
            
            
                | 145 |  |  |      * @return string | 
            
                                                                        
                            
            
                                    
            
            
                | 146 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 147 |  |  |     public function getFullName(): string | 
            
                                                                        
                            
            
                                    
            
            
                | 148 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 149 |  |  |         return $this->fullName; | 
            
                                                                        
                            
            
                                    
            
            
                | 150 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 151 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 152 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 153 |  |  |      * Return the client name | 
            
                                                                        
                            
            
                                    
            
            
                | 154 |  |  |      * @return string | 
            
                                                                        
                            
            
                                    
            
            
                | 155 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 156 |  |  |     public function getClientName(): string | 
            
                                                                        
                            
            
                                    
            
            
                | 157 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 158 |  |  |         return $this->clientName; | 
            
                                                                        
                            
            
                                    
            
            
                | 159 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 160 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 161 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 162 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 163 |  |  |      * Get the checksum of the file | 
            
                                                                        
                            
            
                                    
            
            
                | 164 |  |  |      * @return string | 
            
                                                                        
                            
            
                                    
            
            
                | 165 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 166 |  |  |     public function getChecksum(): string | 
            
                                                                        
                            
            
                                    
            
            
                | 167 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 168 |  |  |         return $this->checksum; | 
            
                                                                        
                            
            
                                    
            
            
                | 169 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 170 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 171 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 172 |  |  |      * Return the name of the file without extension | 
            
                                                                        
                            
            
                                    
            
            
                | 173 |  |  |      * @return string | 
            
                                                                        
                            
            
                                    
            
            
                | 174 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 175 |  |  |     public function getName(): string | 
            
                                                                        
                            
            
                                    
            
            
                | 176 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 177 |  |  |         return $this->name; | 
            
                                                                        
                            
            
                                    
            
            
                | 178 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 179 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 180 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 181 |  |  |      * Return the extension of the file | 
            
                                                                        
                            
            
                                    
            
            
                | 182 |  |  |      * @return string | 
            
                                                                        
                            
            
                                    
            
            
                | 183 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 184 |  |  |     public function getExtension(): string | 
            
                                                                        
                            
            
                                    
            
            
                | 185 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 186 |  |  |         return $this->extension; | 
            
                                                                        
                            
            
                                    
            
            
                | 187 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 188 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 189 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 190 |  |  |      * Return the mime type of the file | 
            
                                                                        
                            
            
                                    
            
            
                | 191 |  |  |      * @return string | 
            
                                                                        
                            
            
                                    
            
            
                | 192 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 193 |  |  |     public function getMimeType(): string | 
            
                                                                        
                            
            
                                    
            
            
                | 194 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 195 |  |  |         return $this->mimeType; | 
            
                                                                        
                            
            
                                    
            
            
                | 196 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 197 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 198 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 199 |  |  |      * Return the file error code | 
            
                                                                        
                            
            
                                    
            
            
                | 200 |  |  |      * @return int | 
            
                                                                        
                            
            
                                    
            
            
                | 201 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 202 |  |  |     public function getError(): int | 
            
                                                                        
                            
            
                                    
            
            
                | 203 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 204 |  |  |         return $this->error; | 
            
                                                                        
                            
            
                                    
            
            
                | 205 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 206 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 207 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 208 |  |  |      * Return the file size in byte | 
            
                                                                        
                            
            
                                    
            
            
                | 209 |  |  |      * @return int | 
            
                                                                        
                            
            
                                    
            
            
                | 210 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 211 |  |  |     public function getSize(): int | 
            
                                                                        
                            
            
                                    
            
            
                | 212 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 213 |  |  |         return $this->size; | 
            
                                                                        
                            
            
                                    
            
            
                | 214 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 215 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 216 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 217 |  |  |      * Return the file full path | 
            
                                                                        
                            
            
                                    
            
            
                | 218 |  |  |      * @return string | 
            
                                                                        
                            
            
                                    
            
            
                | 219 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 220 |  |  |     public function getPath(): string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 221 |  |  |     { | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 222 |  |  |         return $this->path; | 
            
                                                                        
                                                                
            
                                    
            
            
                | 223 |  |  |     } | 
            
                                                                        
                                                                
            
                                    
            
            
                | 224 |  |  | } | 
            
                                                                        
                                                                
            
                                    
            
            
                | 225 |  |  |  | 
            
                        
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
$accountIdthat can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to theidproperty of an instance of theAccountclass. 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.