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

ImagineSupportedFilePath::isValidFilePath()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 4

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 7
c 1
b 0
f 0
dl 0
loc 12
ccs 7
cts 7
cp 1
rs 10
cc 4
nc 3
nop 1
crap 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