Completed
Push — master ( 42303c...e671cd )
by Peter
01:28
created

ErrorException::wrap()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 1
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
    /**
42
     * @param \Exception $e
43
     *
44
     * @return ErrorException
45
     */
46 5
    public static function wrap(\Exception $e)
47
    {
48 5
        return new self($e->getMessage(), $e->getCode(), $e);
49
    }
50
}
51