Browser   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
dl 0
loc 58
ccs 15
cts 15
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A get() 0 16 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\MyAnimeListBrowserBundle\Service;
12
13
use GuzzleHttp\Client as HttpClient;
14
15
class Browser
16
{
17
    /**
18
     * @var HttpClient
19
     */
20
    private $client;
21
22
    /**
23
     * @var ErrorDetector
24
     */
25
    private $detector;
26
27
    /**
28
     * @var string
29
     */
30
    private $host;
31
32
    /**
33
     * @var string
34
     */
35
    private $app_client;
36
37
    /**
38
     * @param HttpClient    $client
39
     * @param ErrorDetector $detector
40
     * @param string        $host
41
     * @param string        $app_client
42
     */
43 3
    public function __construct(HttpClient $client, ErrorDetector $detector, $host, $app_client)
44
    {
45 3
        $this->client = $client;
46 3
        $this->detector = $detector;
47 3
        $this->host = $host;
48 3
        $this->app_client = $app_client;
49 3
    }
50
51
    /**
52
     * @param string $path
53
     * @param array  $options
54
     *
55
     * @return string
56
     */
57 3
    public function get($path, array $options = [])
58
    {
59 3
        if ($this->app_client) {
60 3
            $options['headers'] = array_merge(
61 3
                ['User-Agent' => $this->app_client],
62 3
                isset($options['headers']) ? $options['headers'] : []
63
            );
64
        }
65
66
        try {
67 3
            $response = $this->client->request('GET', $this->host.$path, $options);
68 1
        } catch (\Exception $e) {
69 1
            throw $this->detector->wrap($e);
70
        }
71
72 2
        return $this->detector->detect($response);
73
    }
74
}
75