PrerenderClient::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 4
dl 0
loc 6
ccs 4
cts 4
cp 1
crap 1
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace MediaMonks\Crawler\Client;
4
5
use Symfony\Component\BrowserKit\History;
6
use Symfony\Component\BrowserKit\CookieJar;
7
use Symfony\Component\BrowserKit\Request;
8
9
class PrerenderClient extends GoutteClient
10
{
11
    /**
12
     * @var string
13
     */
14
    protected $prerenderUrl;
15
16
    /**
17
     * @param string $prerenderUrl The url of the prerender server
18
     * @param array $server The server parameters (equivalent of $_SERVER)
19
     * @param History $history A History instance to store the browser history
20
     * @param CookieJar $cookieJar A CookieJar instance to store the cookies
21
     */
22 4
    public function __construct($prerenderUrl, array $server = [], History $history = null, CookieJar $cookieJar = null)
23
    {
24 4
        $this->prerenderUrl = $prerenderUrl;
25
26 4
        parent::__construct($server, $history, $cookieJar);
27 4
    }
28
29
    /**
30
     * @param string $uri
31
     * @return string
32
     */
33 2
    protected function getAbsoluteUri($uri)
34
    {
35 2
        return $this->prerenderUrl.parent::getAbsoluteUri($uri);
36
    }
37
38
    /**
39
     * @inheritdoc
40
     */
41 2
    public function getRequest()
42
    {
43 2
        $request = parent::getRequest();
44 2
        if (!empty($request)) {
45 1
            return new Request($this->correctUrl($request->getUri()),
46 1
                $request->getMethod(), $request->getParameters(),
47 1
                $request->getFiles(), $request->getCookies(), $request->getServer(),
48 1
                $request->getContent());
49
        }
50 1
    }
51
52
    /**
53
     * @param $url
54
     *
55
     * @return string
56
     */
57 1
    protected function correctUrl($url)
58
    {
59 1
        return str_replace($this->prerenderUrl, '', $url);
60
    }
61
}
62