ClientBridge::sendAsync()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 2
ccs 0
cts 1
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 0
nc 1
nop 2
crap 2
1
<?php
2
3
namespace ByTIC\MFinante\Clients\PhantomJs;
4
5
use GuzzleHttp\ClientInterface as GuzzleClientInterface;
6
use JonnyW\PhantomJs\Client as PhantomJsBaseClient;
7
use PhantomInstaller\PhantomBinary;
8
use Psr\Http\Message\RequestInterface;
9
10
/**
11
 * Class PhantomJsClientBridge
12
 * @package ByTIC\MFinante\Clients
13
 */
14
class ClientBridge implements GuzzleClientInterface
15
{
16
    protected $phantomJsClient = null;
17
18
    /**
19
     * @inheritdoc
20
     */
21 2
    public function request($method, $uri = '', array $options = [])
22
    {
23 2
        $client = $this->getPhantomJsClient();
24
25
        /**
26
         * @see \JonnyW\PhantomJs\Http\Request
27
         **/
28 2
        $request = $client->getMessageFactory()->createRequest($uri, $method);
29 2
        $request->addHeader(
30 2
            'User-Agent',
31 2
            'Mozilla/5.0 (Windows NT 10.0; WOW64; rv:50.0) Gecko/20100101 Firefox/50.0'
32
        );
33
        /** IMPORTANT - the delay is necessary to make sure the javascript is all loaded */
34 2
        $request->setDelay(12);
35
36
        /**
37
         * @see \JonnyW\PhantomJs\Http\Response
38
         **/
39 2
        $response = $client->getMessageFactory()->createResponse();
40
41
        // Send the request
42 2
        $client->send($request, $response);
43
44 2
        return ResponseFormatter::format($response);
45
    }
46
47
    /**
48
     * @inheritdoc
49
     */
50
    public function requestAsync($method, $uri = '', array $options = [])
51
    {
52
    }
53
54
    /**
55
     * @inheritdoc
56
     */
57
    public function send(RequestInterface $request, array $options = [])
58
    {
59
    }
60
61
    /**
62
     * @inheritdoc
63
     */
64
    public function sendAsync(RequestInterface $request, array $options = [])
65
    {
66
    }
67
68
    /**
69
     * @inheritdoc
70
     */
71
    public function getConfig($option = null)
72
    {
73
    }
74
75
    /**
76
     * @return PhantomJsBaseClient|null
77
     */
78 2
    protected function getPhantomJsClient()
79
    {
80 2
        if ($this->phantomJsClient === null) {
81 2
            $this->phantomJsClient = PhantomJsBaseClient::getInstance();
82 2
            $this->phantomJsClient->getEngine()->setPath(PhantomBinary::getBin());
83
        }
84 2
        return $this->phantomJsClient;
85
    }
86
}
87