| Total Complexity | 3 |
| Total Lines | 49 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 15 | class MimeType extends AbstractValidator |
||
| 16 | { |
||
| 17 | |||
| 18 | /** |
||
| 19 | * Index in the $_FILES array |
||
| 20 | * |
||
| 21 | * @var string |
||
| 22 | */ |
||
| 23 | private $file = ''; |
||
| 24 | |||
| 25 | /** |
||
| 26 | * Available mime types |
||
| 27 | * |
||
| 28 | * @var array |
||
| 29 | */ |
||
| 30 | private $requiredTypes = []; |
||
| 31 | |||
| 32 | /** |
||
| 33 | * Constructor |
||
| 34 | * |
||
| 35 | * @param array $types |
||
| 36 | * mime type constraint for the file |
||
| 37 | * @codeCoverageIgnore |
||
| 38 | */ |
||
| 39 | public function __construct(array $types) |
||
| 40 | { |
||
| 41 | $this->requiredTypes = $types; |
||
| 42 | } |
||
| 43 | |||
| 44 | /** |
||
| 45 | * |
||
| 46 | * {@inheritdoc} |
||
| 47 | * @see \Mezon\Security\Validators\ValidatorInterface::valid() |
||
| 48 | */ |
||
| 49 | public function valid(): bool |
||
| 50 | { |
||
| 51 | $this->validateFilesFieldExists($this->file); |
||
| 52 | |||
| 53 | return in_array(mime_content_type($_FILES[$this->file]['tmp_name']), $this->requiredTypes); |
||
| 54 | } |
||
| 55 | |||
| 56 | /** |
||
| 57 | * |
||
| 58 | * {@inheritdoc} |
||
| 59 | * @see \Mezon\Security\Validators\ValidatorInterface::setValidatingData() |
||
| 60 | */ |
||
| 61 | public function setValidatingData($data): void |
||
| 64 | } |
||
| 65 | } |