Throws::throwing()   B
last analyzed

Complexity

Conditions 8
Paths 7

Size

Total Lines 23
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 19
dl 0
loc 23
rs 8.4444
c 0
b 0
f 0
cc 8
nc 7
nop 2
1
<?php
2
/**
3
 * SW client throws
4
 * User: moyo
5
 * Date: 2018/7/2
6
 * Time: 3:22 PM
7
 */
8
9
namespace Carno\HTTP\Powered\Swoole\Chips;
10
11
use Carno\HTTP\Exception\ConnectionRefusedException;
12
use Carno\HTTP\Exception\ConnectionTimeoutException;
13
use Carno\HTTP\Exception\RequestCancelledException;
14
use Carno\HTTP\Exception\RequestException;
15
use Carno\HTTP\Exception\RequestFailedException;
16
use Carno\HTTP\Exception\RequestInterruptedException;
17
use Carno\HTTP\Exception\RequestTimeoutException;
18
use Carno\HTTP\Exception\ResponseException;
19
use Carno\HTTP\Exception\UnknownResponseException;
20
use Psr\Http\Message\RequestInterface as Request;
21
use Swoole\Http\Client as SWHClient;
0 ignored issues
show
Bug introduced by
The type Swoole\Http\Client was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
22
23
trait Throws
24
{
25
    /**
26
     * @param Request $request
27
     * @param SWHClient $c
28
     * @throws RequestException
29
     * @throws ResponseException
30
     */
31
    private function throwing(Request $request, SWHClient $c) : void
32
    {
33
        $url = (string) $request->getUri();
34
35
        switch ($c->statusCode) {
36
            case -1:
37
                switch ($c->errCode) {
38
                    case 61:
39
                        throw new ConnectionRefusedException($url); // darwin kernel
40
                    case 110:
41
                        throw new ConnectionTimeoutException($url);
42
                    case 111:
43
                        throw new ConnectionRefusedException($url);
44
                }
45
                throw new RequestFailedException(sprintf('#%d::%s', $c->errCode, $url));
46
            case -2:
47
                throw new RequestTimeoutException($url);
48
            case -3:
49
                throw $this->closing
50
                    ? new RequestCancelledException($url)
51
                    : new RequestInterruptedException($url);
52
            default:
53
                throw new UnknownResponseException($url);
54
        }
55
    }
56
}
57