Passed
Push — master ( 8db740...560e9d )
by Peter
02:03
created

Browser::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 5
cts 5
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 4
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\SmotretAnimeBrowserBundle\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 $prefix;
31
32
    /**
33
     * @var string
34
     */
35
    private $app_client;
36
37
    /**
38
     * @param Client $client
39
     * @param string $host
40
     * @param string $prefix
41
     * @param string $app_client
42
     */
43 1
    public function __construct(Client $client, $host, $prefix, $app_client)
44
    {
45 1
        $this->client = $client;
46 1
        $this->host = $host;
47 1
        $this->prefix = $prefix;
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
        $options['headers'] = isset($options['headers']) ? $options['headers'] : [];
60 1
        $options['headers']['User-Agent'] = $this->app_client;
61
62 1
        $response = $this->client->request('GET', $this->host.$this->prefix.$path, $options);
63
64 1
        $content = $response->getBody()->getContents();
65
66 1
        return json_decode($content, true);
67
    }
68
}
69