| Conditions | 3 |
| Paths | 3 |
| Total Lines | 21 |
| Code Lines | 11 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 35 | public function validate(UploadedFile $file) |
||
| 36 | { |
||
| 37 | // Check allowed types. |
||
| 38 | $fileExtension = $file->getClientOriginalExtension(); |
||
| 39 | $guessedFileExtension = $file->guessExtension(); |
||
| 40 | |||
| 41 | if ($fileExtension !== $guessedFileExtension) { |
||
| 42 | $this->errors[] = 'File extension does not match mime type extension'; |
||
| 43 | |||
| 44 | return false; |
||
| 45 | } |
||
| 46 | |||
| 47 | $extension = strtolower($fileExtension); |
||
| 48 | if (!in_array($extension, $this->allowedTypes)) { |
||
| 49 | $this->errors[] = 'Files of "' . $extension . '" type are not allowed'; |
||
| 50 | |||
| 51 | return false; |
||
| 52 | } |
||
| 53 | |||
| 54 | return true; |
||
| 55 | } |
||
| 56 | |||
| 80 | } |