Completed
Push — master ( e4a414...d6bcbc )
by Peter
05:51
created

Browser::setTimeout()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 5
c 0
b 0
f 0
ccs 3
cts 3
cp 1
rs 9.4285
cc 1
eloc 3
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\WorldArtBrowserBundle\Service;
12
13
use GuzzleHttp\Client;
14
15
class Browser
16
{
17
    /**
18
     * @var Client
19
     */
20
    private $client;
21
22
    /**
23
     * @var ResponseRepair
24
     */
25
    private $repair;
26
27
    /**
28
     * @var string
29
     */
30
    private $host;
31
32
    /**
33
     * @var string
34
     */
35
    private $app_client;
36
37
    /**
38
     * @param Client         $client
39
     * @param ResponseRepair $repair
40
     * @param string         $host
41
     * @param string         $app_client
42
     */
43 1
    public function __construct(Client $client, ResponseRepair $repair, $host, $app_client)
44
    {
45 1
        $this->client = $client;
46 1
        $this->repair = $repair;
47 1
        $this->host = $host;
48 1
        $this->app_client = $app_client;
49 1
    }
50
51
    /**
52
     * @param string $path
53
     * @param array  $options
54
     *
55
     * @return string
56
     */
57 1
    public function get($path, array $options = [])
58
    {
59 1
        if ($this->app_client) {
60 1
            $options['headers'] = isset($options['headers']) ? $options['headers'] : [];
61 1
            $options['headers']['User-Agent'] = $this->app_client;
62
        }
63
64 1
        $response = $this->client->request('GET', $this->host.$path, $options);
65
66 1
        $content = $response->getBody()->getContents();
67
68 1
        return $this->repair->repair($content);
69
    }
70
}
71