UploadValidator   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 7
lcom 0
cbo 1
dl 0
loc 33
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B maxDimension() 0 20 7
1
<?php
2
namespace App\Model\Validation;
3
4
use Cake\Validation\Validator;
5
6
class UploadValidator extends Validator
7
{
8
9
    /**
10
     * Check the dimensions of a file image.
11
     *
12
     * @param array $check  Value to check.
13
     * @param int   $height Max height dimension.
14
     * @param int   $width  Max width dimension.
15
     *
16
     * @return bool
17
     */
18
    public static function maxDimension($check, $height, $width)
19
    {
20
        if (is_array($check) && isset($check['error']) && (int)$check['error'] === UPLOAD_ERR_NO_FILE) {
21
            return true;
22
        }
23
24
        if (!is_file($check['tmp_name'])) {
25
            return false;
26
        }
27
28
        //@codingStandardsIgnoreStart
29
        $size = @getimagesize($check['tmp_name']);
30
        //@codingStandardsIgnoreEnd
31
32
        if (!is_array($size)) {
33
            return false;
34
        }
35
36
        return ($size[0] <= (int)$width && $size[1] <= (int)$height);
37
    }
38
}
39