Total Complexity | 4 |
Total Lines | 62 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | <?php |
||
15 | class ImageMaximumWidthHeight extends AbstractValidator |
||
16 | { |
||
17 | |||
18 | /** |
||
19 | * Index in the $_FILES array |
||
20 | * |
||
21 | * @var string |
||
22 | */ |
||
23 | private $file = ''; |
||
24 | |||
25 | /** |
||
26 | * Maximum width of the image |
||
27 | * |
||
28 | * @var integer |
||
29 | */ |
||
30 | private $maximumWidth = 0; |
||
31 | |||
32 | /** |
||
33 | * Maximum height of the image |
||
34 | * |
||
35 | * @var integer |
||
36 | */ |
||
37 | private $maximumHeight = 0; |
||
38 | |||
39 | /** |
||
40 | * Constructor |
||
41 | * |
||
42 | * @param int $width |
||
43 | * width constraint for the file |
||
44 | * @param int $height |
||
45 | * height constraint for the file |
||
46 | * @codeCoverageIgnore |
||
47 | */ |
||
48 | public function __construct(int $width, int $height) |
||
53 | } |
||
54 | |||
55 | /** |
||
56 | * |
||
57 | * {@inheritdoc} |
||
58 | * @see \Mezon\Security\Validators\ValidatorInterface::valid() |
||
59 | */ |
||
60 | public function valid(): bool |
||
61 | { |
||
62 | $this->validateFilesFieldExists($this->file); |
||
63 | |||
64 | list($width, $height) = getimagesize($_FILES[$this->file]['tmp_name']); |
||
65 | |||
66 | return $width <= $this->maximumWidth && $height <= $this->maximumHeight; |
||
67 | } |
||
68 | |||
69 | /** |
||
70 | * |
||
71 | * {@inheritdoc} |
||
72 | * @see \Mezon\Security\Validators\ValidatorInterface::setValidatingData() |
||
73 | */ |
||
74 | public function setValidatingData($data): void |
||
77 | } |
||
78 | } |