Code Duplication    Length = 41-42 lines in 2 locations

src/Transport/HttpGuzzle/GuzzleTransport.php 1 location

@@ 30-71 (lines=42) @@
27
 * @package Elastification\Client\Transport\HttpGuzzle
28
 * @author  Mario Mueller
29
 */
30
class GuzzleTransport implements TransportInterface
31
{
32
    /**
33
     * @var ClientInterface
34
     */
35
    private $guzzleClient;
36
37
    /**
38
     * @param ClientInterface $guzzleClient
39
     */
40
    public function __construct(ClientInterface $guzzleClient)
41
    {
42
        $this->guzzleClient = $guzzleClient;
43
    }
44
45
    /**
46
     * @param string $httpMethod The http method to use.
47
     *
48
     * @return TransportRequestInterface
49
     * @author Mario Mueller
50
     */
51
    public function createRequest($httpMethod)
52
    {
53
        return new GuzzleTransportRequest(new Request($httpMethod, ''));
54
    }
55
56
    /**
57
     * @param TransportRequestInterface $request The configured request to send.
58
     *
59
     * @throws \Elastification\Client\Exception\ClientException
60
     * @return \Elastification\Client\Transport\TransportResponseInterface
61
     * @author Mario Mueller
62
     */
63
    public function send(TransportRequestInterface $request)
64
    {
65
        try {
66
            return new GuzzleTransportResponse($this->guzzleClient->send($request->getWrappedRequest()));
67
        } catch (\Exception $exception) {
68
            throw new TransportLayerException($exception->getMessage(), $exception->getCode(), $exception);
69
        }
70
    }
71
}
72

src/Transport/Thrift/ThriftTransport.php 1 location

@@ 33-73 (lines=41) @@
30
 * @package Elastification\Client\Transport\Thrift
31
 * @author  Mario Mueller
32
 */
33
class ThriftTransport implements TransportInterface
34
{
35
    /**
36
     * @var RestClient
37
     */
38
    private $thriftClient;
39
40
    /**
41
     * @param RestClient $thriftClient
42
     */
43
    function __construct(RestClient $thriftClient)
44
    {
45
        $this->thriftClient = $thriftClient;
46
    }
47
48
    /**
49
     * @param string $httpMethod The http method to use.
50
     *
51
     * @return \Elastification\Client\Transport\TransportRequestInterface
52
     * @author Mario Mueller
53
     */
54
    public function createRequest($httpMethod)
55
    {
56
        return new ThriftTransportRequest($httpMethod);
57
    }
58
59
    /**
60
     * @param TransportRequestInterface $request The configured request to send.
61
     *
62
     * @return \Elastification\Client\Transport\TransportResponseInterface
63
     * @author Mario Mueller
64
     */
65
    public function send(TransportRequestInterface $request)
66
    {
67
        try {
68
            return new ThriftTransportResponse($this->thriftClient->execute($request->getWrappedRequest()));
69
        } catch (\Exception $exception) {
70
            throw new TransportLayerException($exception->getMessage(), $exception->getCode(), $exception);
71
        }
72
    }
73
}
74