Scrutinizer GitHub App not installed

We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.

Install GitHub App

Completed
Pull Request — master (#1111)
by Henrique
03:23 queued 45s
created

Image   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Test Coverage

Coverage 81.82%

Importance

Changes 0
Metric Value
wmc 6
eloc 9
dl 0
loc 35
ccs 9
cts 11
cp 0.8182
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 2
A validate() 0 15 4
1
<?php
2
3
/*
4
 * This file is part of Respect/Validation.
5
 *
6
 * (c) Alexandre Gomes Gaigalas <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the "LICENSE.md"
9
 * file that was distributed with this source code.
10
 */
11
12
declare(strict_types=1);
13
14
namespace Respect\Validation\Rules;
15
16
use finfo;
17
use SplFileInfo;
18
use function is_file;
19
use function is_string;
20
use function mb_strpos;
21
22
/**
23
 * Validates if the file is a valid image by checking its MIME type.
24
 *
25
 * @author Danilo Benevides <[email protected]>
26
 * @author Guilherme Siani <[email protected]>
27
 * @author Henrique Moody <[email protected]>
28
 */
29
final class Image extends AbstractRule
30
{
31
    /**
32
     * @var finfo
33
     */
34
    private $fileInfo;
35
36
    /**
37
     * Initializes the rule.
38
     *
39
     * @param finfo|null $fileInfo
40
     */
41 1
    public function __construct(finfo $fileInfo = null)
42
    {
43 1
        $this->fileInfo = $fileInfo ?: new finfo(FILEINFO_MIME_TYPE);
44 1
    }
45
46
    /**
47
     * {@inheritdoc}
48
     */
49 1
    public function validate($input): bool
50
    {
51 1
        if ($input instanceof SplFileInfo) {
52
            return $this->validate($input->getPathname());
53
        }
54
55 1
        if (!is_string($input)) {
56 1
            return false;
57
        }
58
59 1
        if (!is_file($input)) {
60
            return false;
61
        }
62
63 1
        return 0 === mb_strpos($this->fileInfo->file($input), 'image/');
64
    }
65
}
66