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

HttpWorker::support()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
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
}