Completed
Push — master ( 6823cc...a3f6d1 )
by Peter
01:40
created

ErrorDetector::detect()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 18
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 4

Importance

Changes 0
Metric Value
dl 0
loc 18
ccs 9
cts 9
cp 1
rs 9.2
c 0
b 0
f 0
cc 4
eloc 13
nc 4
nop 1
crap 4
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\AniDbBrowserBundle\Util;
12
13
use AnimeDb\Bundle\AniDbBrowserBundle\Exception\BannedException;
14
use AnimeDb\Bundle\AniDbBrowserBundle\Exception\NotFoundException;
15
use AnimeDb\Bundle\AniDbBrowserBundle\Exception\ErrorException;
16
17
class ErrorDetector
18
{
19
    /**
20
     * @param string $response
21
     *
22
     * @return string
23
     */
24 4
    public function detect($response)
25
    {
26 4
        if (!preg_match('/<body><error>([^<>]+)<\/error><\/body>/im', $response, $match)) {
27 1
            return $response;
28
        }
29
30 3
        switch ($match[1]) {
31 3
            case 'Banned':
32 1
                throw BannedException::banned();
33
                break;
0 ignored issues
show
Unused Code introduced by
break; does not seem to be reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
34 2
            case 'Anime not found':
35 1
                throw NotFoundException::anime();
36
                break;
0 ignored issues
show
Unused Code introduced by
break; does not seem to be reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
37
            default:
38 1
                throw ErrorException::error($match[1]);
39
                break;
0 ignored issues
show
Unused Code introduced by
break; does not seem to be reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
40
        }
41
    }
42
}
43