Completed
Push — master ( 0be8e1...585ca2 )
by Daniel
59:26 queued 46:02
created

ImagineSupportedFilePath   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 13
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
eloc 8
dl 0
loc 13
ccs 0
cts 7
cp 0
rs 10
c 0
b 0
f 0
wmc 4

1 Method

Rating   Name   Duplication   Size   Complexity  
A isValidFilePath() 0 11 4
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