Image::process()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

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