Conditions | 6 |
Paths | 5 |
Total Lines | 24 |
Lines | 0 |
Ratio | 0 % |
Tests | 14 |
CRAP Score | 6.0106 |
Changes | 0 |
1 | <?php |
||
25 | 8 | public function validate($value, string $valueIdentifier = null) |
|
26 | { |
||
27 | 8 | $this->value = $value; |
|
28 | 8 | $ratio = RuleHelper::normalizeImageRatio($this->options[self::OPTION_RATIO]); |
|
29 | 8 | if (! is_array($value) || ! isset($value['tmp_name'])) { |
|
30 | $this->success = false; |
||
31 | 8 | } elseif (! file_exists($value['tmp_name'])) { |
|
32 | 2 | $this->success = $value['error'] === UPLOAD_ERR_NO_FILE; |
|
33 | 6 | } elseif ($ratio == 0) { |
|
34 | 2 | $this->success = true; |
|
35 | } else { |
||
36 | 4 | $imageInfo = getimagesize($value['tmp_name']); |
|
37 | |||
38 | 4 | if (is_array($imageInfo)) { |
|
39 | 3 | $actualRatio = $imageInfo[0] / $imageInfo[1]; |
|
40 | 3 | $this->success = abs($actualRatio - $ratio) <= $this->options[self::OPTION_ERROR_MARGIN]; |
|
41 | } else { |
||
42 | // no image size computed => no valid image |
||
43 | 1 | return $this->success = false; |
|
44 | } |
||
45 | } |
||
46 | |||
47 | 7 | return $this->success; |
|
48 | } |
||
49 | } |
||
50 |