Completed
Push — master ( 390e4e...b0ec12 )
by Taosikai
12:57
created

HttpTunnelClient   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 3
c 0
b 0
f 0
lcom 1
cbo 3
dl 0
loc 26
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A handleConnectLocalError() 0 6 1
A makeErrorResponse() 0 7 2
1
<?php
2
/**
3
 * Spike library
4
 * @author Tao <[email protected]>
5
 */
6
namespace Spike\Client\TunnelClient;
7
8
use GuzzleHttp\Psr7\Response;
9
use GuzzleHttp\Psr7;
10
11
class HttpTunnelClient extends TunnelClient
12
{
13
    /**
14
     * {@inheritdoc}
15
     */
16
    public function handleConnectLocalError(\Exception $exception)
17
    {
18
        $response = $this->makeErrorResponse(500, $exception->getMessage());
19
        $this->proxyConnection->end(Psr7\str($response));
20
//        $this->close();
21
    }
22
23
    /**
24
     * Make an error psr7 response
25
     * @param int $code
26
     * @param string $message
27
     * @return Response
28
     */
29
    protected function makeErrorResponse($code, $message)
30
    {
31
        $message = $message ?: 'Proxy error';
32
        return new Response($code, [
33
            'Content-Length' => strlen($message)
34
        ], $message);
35
    }
36
}