Test Failed
Pull Request — master (#19)
by Flo
03:56
created

Image   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 1
dl 0
loc 40
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A process() 0 9 2
1
<?php
2
/**
3
 * Class ImageEntity | ImageEntity.php
4
 * @package Faulancer\Form\Validator\Base
5
 * @author Florian Knapp <[email protected]>
6
 */
7
namespace Faulancer\Form\Validator\Base;
8
9
use Faulancer\Form\Validator\AbstractValidator;
10
11
/**
12
 * Class ImageEntity
13
 */
14
class Image extends AbstractValidator
15
{
16
17
    /**
18
     * The error message as key for translation
19
     * @var string
20
     */
21
    protected $errorMessage = 'validator_invalid_image_type';
22
23
    /**
24
     * Valid image mime-types
25
     * @var array
26
     */
27
    private $validImageMimeTypes = [
28
        'image/jpg',
29
        'image/jpeg',
30
        'image/png',
31
        'image/gif',
32
        'image/tiff',
33
        'image/psd',
34
        'image/x-icon',
35
        'image/svg+xml'
36
    ];
37
38
    /**
39
     * Validate image type within it's mime-type
40
     * @param string $data
41
     * @return boolean
42
     */
43
    public function process($data)
44
    {
45
        if (!file_exists($data)) {
46
            return false;
47
        }
48
49
        $data = mime_content_type($data);
50
        return in_array($data, $this->validImageMimeTypes);
51
    }
52
53
}