Completed
Push — master ( 0be8e1...585ca2 )
by Daniel
59:26 queued 46:02
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
declare(strict_types=1);
4
5
namespace Silverback\ApiComponentBundle\Validator;
6
7
class ImagineSupportedFilePath
8
{
9
    public static function isValidFilePath(?string $filePath): bool
10
    {
11
        if (!$filePath || !file_exists($filePath)) {
12
            return false;
13
        }
14
        try {
15
            $imageType = \exif_imagetype($filePath);
16
        } catch (\Exception $e) {
17
            return false;
18
        }
19
        return \in_array($imageType, [IMAGETYPE_JPEG, IMAGETYPE_JPEG2000, IMAGETYPE_PNG, IMAGETYPE_GIF], true);
20
    }
21
}
22