Completed
Push — master ( 77fa8f...cc9988 )
by
unknown
03:01
created

PrerenderClient   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 93.75%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 2
dl 0
loc 53
ccs 15
cts 16
cp 0.9375
rs 10
c 0
b 0
f 0

4 Methods

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