Completed
Push — master ( 143878...f45699 )
by Taosikai
14:33
created

HttpWorker   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A resolveTargetHost() 0 4 1
A handleConnectLocalError() 0 6 1
A makeErrorResponse() 0 8 2
A support() 0 4 1
1
<?php
2
3
/*
4
 * This file is part of the slince/spike package.
5
 *
6
 * (c) Slince <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Spike\Client\Worker;
13
14
use GuzzleHttp\Psr7;
15
use Spike\Common\Tunnel\HttpTunnel;
16
use Spike\Common\Tunnel\TunnelInterface;
17
18
class HttpWorker extends TcpWorker
19
{
20
    /**
21
     * {@inheritdoc}
22
     */
23
    public function resolveTargetHost()
24
    {
25
        return $this->tunnel->getForwardHost($this->tunnel->getProxyHost());
0 ignored issues
show
Bug introduced by
The method getProxyHost() does not seem to exist on object<Spike\Common\Tunnel\TcpTunnel>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
Bug introduced by
The method getForwardHost() does not seem to exist on object<Spike\Common\Tunnel\TcpTunnel>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
26
    }
27
28
    /**
29
     * {@inheritdoc}
30
     */
31
    public function handleConnectLocalError(\Exception $exception)
32
    {
33
        $response = $this->makeErrorResponse(500, $exception->getMessage());
34
        $this->proxyConnection->end(Psr7\str($response));
35
        $this->stop();
36
    }
37
38
    /**
39
     * Make an error psr7 response.
40
     *
41
     * @param int    $code
42
     * @param string $message
43
     *
44
     * @return Psr7\Response
45
     */
46
    protected function makeErrorResponse($code, $message)
47
    {
48
        $message = $message ?: sprintf('Cannot connect to "%s"', $this->resolveTargetHost());
49
50
        return new Psr7\Response($code, [
51
            'Content-Length' => strlen($message),
52
        ], $message);
53
    }
54
55
    /**
56
     * {@inheritdoc}
57
     */
58
    public static function support(TunnelInterface $tunnel)
59
    {
60
        $tunnel instanceof HttpTunnel;
61
    }
62
}