Browser   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 71
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 3
dl 0
loc 71
ccs 18
cts 18
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 13 1
A get() 0 16 3
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 as HttpClient;
14
15
class Browser
16
{
17
    /**
18
     * @var HttpClient
19
     */
20
    private $client;
21
22
    /**
23
     * @var ResponseRepair
24
     */
25
    private $repair;
26
27
    /**
28
     * @var ErrorDetector
29
     */
30
    private $detector;
31
32
    /**
33
     * @var string
34
     */
35
    private $host;
36
37
    /**
38
     * @var string
39
     */
40
    private $app_client;
41
42
    /**
43
     * @param HttpClient     $client
44
     * @param ResponseRepair $repair
45
     * @param ErrorDetector  $detector
46
     * @param string         $host
47
     * @param string         $app_client
48
     */
49 2
    public function __construct(
50
        HttpClient $client,
51
        ResponseRepair $repair,
52
        ErrorDetector $detector,
53
        $host,
54
        $app_client
55
    ) {
56 2
        $this->client = $client;
57 2
        $this->repair = $repair;
58 2
        $this->detector = $detector;
59 2
        $this->host = $host;
60 2
        $this->app_client = $app_client;
61 2
    }
62
63
    /**
64
     * @param string $path
65
     * @param array  $options
66
     *
67
     * @return string
68
     */
69 2
    public function get($path, array $options = [])
70
    {
71 2
        if ($this->app_client) {
72 2
            $options['headers'] = array_merge(
73 2
                ['User-Agent' => $this->app_client],
74 2
                isset($options['headers']) ? $options['headers'] : []
75 2
            );
76 2
        }
77
78 2
        $response = $this->client->request('GET', $this->host.$path, $options);
79
80 2
        $content = $this->detector->detect($response, $path, $options);
81 2
        $content = $this->repair->repair($content);
82
83 2
        return $content;
84
    }
85
}
86