Completed
Push — master ( 62c9f8...42303c )
by Peter
01:50
created

ErrorException::failed()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 4
cts 4
cp 1
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 5
nc 2
nop 2
crap 2
1
<?php
2
3
/**
4
 * AnimeDb package.
5
 *
6
 * @author    Peter Gribanov <[email protected]>
7
 * @copyright Copyright (c) 2011, Peter Gribanov
8
 * @license   http://opensource.org/licenses/GPL-3.0 GPL v3
9
 */
10
11
namespace AnimeDb\Bundle\ShikimoriBrowserBundle\Exception;
12
13
class ErrorException extends \RuntimeException
14
{
15
    /**
16
     * @param string $massage
17
     * @param int    $code
18
     *
19
     * @return ErrorException
20
     */
21 2
    public static function failed($massage, $code)
22
    {
23 2
        if ($massage) {
24 1
            return new self(sprintf('Server returned error "%s".', $massage), $code);
25
        } else {
26 1
            return new self('Server returned an error.', $code);
27
        }
28
    }
29
30
    /**
31
     * @param string $massage
32
     * @param int    $code
33
     *
34
     * @return ErrorException
35
     */
36 1
    public static function invalidResponse($massage, $code)
37
    {
38 1
        return new self(sprintf('Failed to parse response due to "%s" error.', $massage), $code);
39
    }
40
}
41