Completed
Push — 2.0 ( a00819...62c098 )
by Peter
07:50 queued 05:05
created

Browser::setResponseCache()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
/**
3
 * AnimeDb package.
4
 *
5
 * @author    Peter Gribanov <[email protected]>
6
 * @copyright Copyright (c) 2011, Peter Gribanov
7
 * @license   http://opensource.org/licenses/GPL-3.0 GPL v3
8
 */
9
namespace AnimeDb\Bundle\AniDbBrowserBundle\Service;
10
11
use AnimeDb\Bundle\AniDbBrowserBundle\Service\Client\ClientInterface;
12
use Symfony\Component\DomCrawler\Crawler;
13
14
/**
15
 * Browser.
16
 *
17
 * @link http://anidb.net/
18
 * @link http://wiki.anidb.net/w/HTTP_API_Definition
19
 */
20
class Browser
21
{
22
    /**
23
     * @var ClientInterface
24
     */
25
    protected $client;
26
27
    /**
28
     * @var string
29
     */
30
    protected $host;
31
32
    /**
33
     * @var string
34
     */
35
    protected $api_host;
36
37
    /**
38
     * @var string
39
     */
40
    protected $image_prefix;
41
42
    /**
43
     * @param ClientInterface $client
44
     * @param string $host
45
     * @param string $api_host
46
     * @param string $image_prefix
47
     */
48 7
    public function __construct(ClientInterface $client, $host, $api_host, $image_prefix)
49
    {
50 7
        $this->client = $client;
51 7
        $this->host = $host;
52 7
        $this->api_host = $api_host;
53 7
        $this->image_prefix = $image_prefix;
54 7
    }
55
56
    /**
57
     * @return string
58
     */
59 1
    public function getHost()
60
    {
61 1
        return $this->host;
62
    }
63
64
    /**
65
     * @return string
66
     */
67 1
    public function getApiHost()
68
    {
69 1
        return $this->api_host;
70
    }
71
72
    /**
73
     * @param int $timeout
74
     *
75
     * @return Browser
76
     */
77 1
    public function setTimeout($timeout)
78
    {
79 1
        $this->client->setTimeout($timeout);
80
81 1
        return $this;
82
    }
83
84
    /**
85
     * @param string $proxy
86
     *
87
     * @return Browser
88
     */
89 1
    public function setProxy($proxy)
90
    {
91 1
        $this->client->setProxy($proxy);
92
93 1
        return $this;
94
    }
95
96
    /**
97
     * @param string $request
98
     * @param array $params
99
     *
100
     * @return string
101
     */
102 2
    public function getContent($request, array $params = [])
103
    {
104 2
        return $this->client->get($request, $params);
105
    }
106
107
    /**
108
     * @param string $request
109
     * @param array $params
110
     *
111
     * @return Crawler
112
     */
113 1
    public function getCrawler($request, array $params = [])
114
    {
115 1
        return new Crawler($this->getContent($request, $params));
116
    }
117
118
    /**
119
     * @param string $image
120
     *
121
     * @return string
122
     */
123 1
    public function getImageUrl($image)
124
    {
125 1
        return $this->image_prefix.$image;
126
    }
127
}
128