GuzzleTransportRequest   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
c 1
b 0
f 0
lcom 1
cbo 3
dl 0
loc 59
ccs 16
cts 16
cp 1
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A setBody() 0 4 1
A getWrappedRequest() 0 4 1
A setPath() 0 5 1
A setQueryParams() 0 5 1
1
<?php
2
/*
3
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
4
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
5
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
6
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
7
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
8
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
9
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
10
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
11
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
12
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
13
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
14
 *
15
 * This software consists of voluntary contributions made by many individuals
16
 * and is licensed under the MIT license.
17
 */
18
namespace Elastification\Client\Transport\HttpGuzzle;
19
20
use Elastification\Client\Transport\TransportRequestInterface;
21
use GuzzleHttp\Psr7\Request;
22
use Psr\Http\Message\RequestInterface;
23
24
/**
25
 * @package Elastification\Client\Transport\HttpGuzzle
26
 * @author  Mario Mueller
27
 */
28
class GuzzleTransportRequest implements TransportRequestInterface
29
{
30
    /**
31
     * @var RequestInterface
32
     */
33
    private $guzzleRequest;
34
35
    /**
36
     * @param RequestInterface $guzzleRequest
37
     */
38 5
    public function __construct(RequestInterface $guzzleRequest)
39
    {
40 5
        $this->guzzleRequest = $guzzleRequest;
41 5
    }
42
43
    /**
44
     * @param string $body The raw request body.
45
     *
46
     * @return void
47
     * @author Mario Mueller
48
     */
49 1
    public function setBody($body)
50
    {
51 1
        $this->guzzleRequest = $this->guzzleRequest->withBody(\GuzzleHttp\Psr7\stream_for($body));
52 1
    }
53
54
    /**
55
     * @param string $path The path according to the Elasticsearch http interface.
56
     *
57
     * @return void
58
     * @author Mario Mueller
59
     */
60 1
    public function setPath($path)
61
    {
62 1
        $uri = $this->guzzleRequest->getUri()->withPath($path);
63 1
        $this->guzzleRequest = new Request($this->guzzleRequest->getMethod(), $uri);
64 1
    }
65
66
    /**
67
     * @return Request
68
     * @author Mario Mueller
69
     */
70 2
    public function getWrappedRequest()
71
    {
72 2
        return $this->guzzleRequest;
73
    }
74
75
    /**
76
     * @param array $params
77
     *
78
     * @return void
79
     * @author Mario Mueller
80
     */
81 2
    public function setQueryParams(array $params)
82
    {
83 2
        $uri = $this->guzzleRequest->getUri()->withQuery(\GuzzleHttp\Psr7\build_query($params));
84 2
        $this->guzzleRequest = $this->guzzleRequest->withUri($uri);
85 2
    }
86
}
87