Passed
Push — master ( 4f7618...5b2171 )
by Peter
03:16
created

Browser   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 47
ccs 12
cts 12
cp 1
rs 10
c 0
b 0
f 0
wmc 4

2 Methods

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