HttpWorker::handleConnectLocalError()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 1
dl 0
loc 6
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\Client\Client;
16
use Spike\Common\Tunnel\HttpTunnel;
17
use Spike\Common\Tunnel\TunnelInterface;
18
use Spike\Version;
19
20
class HttpWorker extends TcpWorker
21
{
22
    /**
23
     * {@inheritdoc}
24
     */
25
    public function resolveTargetHost()
26
    {
27
        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...
28
    }
29
30
    /**
31
     * {@inheritdoc}
32
     */
33
    public function handleConnectLocalError(\Exception $exception)
34
    {
35
        $response = $this->makeErrorResponse(500, $exception->getMessage());
36
        $this->proxyConnection->end(Psr7\str($response));
37
        $this->stop();
38
    }
39
40
    /**
41
     * Make an error psr7 response.
42
     *
43
     * @param int    $code
44
     * @param string $message
45
     *
46
     * @return Psr7\Response
47
     */
48
    protected function makeErrorResponse($code, $message)
49
    {
50
        $message = $message ?: sprintf('Cannot connect to "%s"', $this->resolveTargetHost());
51
52
        return new Psr7\Response($code, [
53
            'Content-Length' => strlen($message),
54
            'X-Spike' => Client::NAME .' '. Version::VERSION,
55
        ], $message);
56
    }
57
58
    /**
59
     * {@inheritdoc}
60
     */
61
    public static function support(TunnelInterface $tunnel)
62
    {
63
        $tunnel instanceof HttpTunnel;
64
    }
65
}