Passed
Branch feature/unit-tests (d28166)
by Daniel
11:16
created

ImagineSupportedFilePath   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 14
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
eloc 8
c 1
b 0
f 0
dl 0
loc 14
ccs 7
cts 7
cp 1
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A isValidFilePath() 0 12 4
1
<?php
2
3
/*
4
 * This file is part of the Silverback API Component Bundle Project
5
 *
6
 * (c) Daniel West <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
declare(strict_types=1);
13
14
namespace Silverback\ApiComponentBundle\Validator;
15
16
/**
17
 * @author Daniel West <[email protected]>
18
 */
19
class ImagineSupportedFilePath
20
{
21 1
    public static function isValidFilePath(?string $filePath): bool
22
    {
23 1
        if (!$filePath || !file_exists($filePath)) {
24 1
            return false;
25
        }
26
        try {
27 1
            $imageType = exif_imagetype($filePath);
28 1
        } catch (\Exception $e) {
29 1
            return false;
30
        }
31
32 1
        return \in_array($imageType, [IMAGETYPE_JPEG, IMAGETYPE_JPEG2000, IMAGETYPE_JP2, IMAGETYPE_PNG, IMAGETYPE_GIF], true);
33
    }
34
}
35