Completed
Push — 2.0 ( 578d41...4d221b )
by Peter
07:06 queued 04:10
created

Browser::get()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 13
Bugs 2 Features 2
Metric Value
c 13
b 2
f 2
dl 0
loc 5
ccs 0
cts 0
cp 0
rs 9.4285
cc 1
eloc 3
nc 1
nop 3
crap 2
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
     * @deprecated get() is deprecated since AniDbBrowser 2.0. Use getCrawler() instead
97
     * @codeCoverageIgnore
98
     *
99
     * @param string $request
100
     * @param array $params
101
     * @param bool $force
102
     *
103
     * @return Crawler
104
     */
105
    public function get($request, array $params = [], $force = false)
0 ignored issues
show
Unused Code introduced by
The parameter $force is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
106
    {
107
        trigger_error('get() is deprecated since AniDbBrowser 2.0. Use getCrawler() instead', E_USER_DEPRECATED);
108
        return $this->getCrawler($request, $params);
109
    }
110
111
    /**
112
     * @param string $request
113
     * @param array $params
114
     *
115
     * @return string
116
     */
117 2
    public function getContent($request, array $params = [])
118
    {
119 2
        return $this->client->get($request, $params);
120
    }
121
122
    /**
123
     * @param string $request
124
     * @param array $params
125
     *
126
     * @return Crawler
127
     */
128 1
    public function getCrawler($request, array $params = [])
129
    {
130 1
        return new Crawler($this->getContent($request, $params));
131
    }
132
133
    /**
134
     * @param string $image
135
     *
136
     * @return string
137
     */
138 1
    public function getImageUrl($image)
139
    {
140 1
        return $this->image_prefix.$image;
141
    }
142
}
143