Completed
Push — develop ( f05cec...11f198 )
by Daniel
07:33
created

ImagineSupportedFilePath::isValidFilePath()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 20

Importance

Changes 0
Metric Value
cc 4
eloc 7
nc 3
nop 1
dl 0
loc 11
ccs 0
cts 7
cp 0
crap 20
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Silverback\ApiComponentBundle\Validator;
4
5
class ImagineSupportedFilePath
6
{
7
    public static function isValidFilePath(?string $filePath): bool
8
    {
9
        if (!$filePath || !file_exists($filePath)) {
10
            return false;
11
        }
12
        try {
13
            $imageType = \exif_imagetype($filePath);
14
        } catch (\Exception $e) {
15
            return false;
16
        }
17
        return \in_array($imageType, [IMAGETYPE_JPEG, IMAGETYPE_JPEG2000, IMAGETYPE_PNG, IMAGETYPE_GIF], true);
18
    }
19
}
20