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