Passed
Push — master ( e4384a...a58594 )
by Peter
02:29
created

ErrorDetector::detect()   A

Complexity

Conditions 3
Paths 1

Size

Total Lines 13
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 13
ccs 7
cts 7
cp 1
rs 9.4285
c 1
b 0
f 0
cc 3
eloc 6
nc 1
nop 1
crap 3
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\MyAnimeListBrowserBundle\Service;
12
13
use AnimeDb\Bundle\MyAnimeListBrowserBundle\Exception\BannedException;
14
use AnimeDb\Bundle\MyAnimeListBrowserBundle\Exception\NotFoundException;
15
use Psr\Http\Message\ResponseInterface;
16
17
class ErrorDetector
18
{
19
    /**
20
     * @param ResponseInterface $response
21
     *
22
     * @return string
23
     */
24 3
    public function detect(ResponseInterface $response)
25
    {
26 3
        if ($response->getStatusCode() == 404) {
27 1
            throw NotFoundException::page();
28
        }
29
30 2
        $content = $response->getBody()->getContents();
31
32 2
        if (strpos($content, 'Access has been restricted for this account.') !== false) {
33 1
            throw BannedException::banned();
34
        }
35
36 1
        return $content;
37
    }
38
}
39