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