Completed
Pull Request — master (#32)
by Krishnaprasad
04:43
created

ClamavValidatorException::forScanResult()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 11
ccs 0
cts 9
cp 0
rs 9.9
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 2
1
<?php namespace Sunspikes\ClamavValidator;
2
3
use Exception;
4
5
class ClamavValidatorException extends Exception
6
{
7
    /**
8
     * @param string $file
9
     */
10 1
    public static function forNonReadableFile($file)
11
    {
12 1
        return new self(
13 1
            sprintf('The file "%s" is not readable', $file)
14 1
        );
15
    }
16
17
    /**
18
     * @param array $result
19
     */
20
    public static function forScanResult($result)
21
    {
22
        return new self(
23
            sprintf(
24
                'ClamAV scanner failed to scan file "%s" with error "%s" (%s)',
25
                $result['filename'],
26
                $result['reason'],
27
                $result['status']
28
            )
29
        );
30
    }
31
32
    /**
33
     * @param \Throwable $exception
34
     */
35
    public static function forClientException($exception)
36
    {
37
        return new self(
38
            sprintf('ClamAV scanner client failed with error "%s"', $exception->getMessage()),
39
            0,
40
            $exception
41
        );
42
    }
43
}
44