• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

sirn-se / websocket-php / 8346487915

19 Mar 2024 04:15PM UTC coverage: 22.584% (-77.4%) from 100.0%
8346487915

push

github

sirn-se
Temp test verification

2 of 2 new or added lines in 1 file covered. (100.0%)

742 existing lines in 32 files now uncovered.

222 of 983 relevant lines covered (22.58%)

0.23 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

38.46
/src/Http/Response.php
1
<?php
2

3
/**
4
 * Copyright (C) 2014-2024 Textalk and contributors.
5
 * This file is part of Websocket PHP and is free software under the ISC License.
6
 */
7

8
namespace WebSocket\Http;
9

10
use Phrity\Net\Uri;
11
use Psr\Http\Message\{
12
    ResponseInterface,
13
    UriInterface
14
};
15
use RuntimeException;
16

17
/**
18
 * Phrity\WebSocket\Http\Response class.
19
 * Only used for handshake procedure.
20
 */
21
class Response extends Message implements ResponseInterface
22
{
23
    private static $codes = [
24
        100 => 'Continue',
25
        101 => 'Switching Protocols',
26
        102 => 'Processing',
27
        103 => 'Early Hints',
28
        200 => 'OK',
29
        201 => 'Created',
30
        202 => 'Accepted',
31
        203 => 'Non-Authoritative Information',
32
        204 => 'No Content',
33
        205 => 'Reset Content',
34
        206 => 'Partial Content',
35
        207 => 'Multi-Status',
36
        208 => 'Already Reported',
37
        226 => 'IM Used',
38
        300 => 'Multiple Choices',
39
        301 => 'Moved Permanently',
40
        302 => 'Found',
41
        303 => 'See Other',
42
        304 => 'Not Modified',
43
        305 => 'Use Proxy',
44
        307 => 'Temporary Redirect',
45
        308 => 'Permanent Redirect',
46
        400 => 'Bad Request',
47
        401 => 'Unauthorized',
48
        402 => 'Payment Required',
49
        403 => 'Forbidden',
50
        404 => 'Not Found',
51
        405 => 'Method Not Allowed',
52
        406 => 'Not Acceptable',
53
        407 => 'Proxy Authentication Required',
54
        408 => 'Request Timeout',
55
        409 => 'Conflict',
56
        410 => 'Gone',
57
        411 => 'Length Required',
58
        412 => 'Precondition Failed',
59
        413 => 'Content Too Large',
60
        414 => 'URI Too Long',
61
        415 => 'Unsupported Media Type',
62
        416 => 'Range Not Satisfiable',
63
        417 => 'Expectation Failed',
64
        421 => 'Misdirected Request',
65
        422 => 'Unprocessable Content',
66
        423 => 'Locked',
67
        424 => 'Failed Dependency',
68
        425 => 'Too Early',
69
        426 => 'Upgrade Required',
70
        428 => 'Precondition Required',
71
        429 => 'Too Many Requests',
72
        431 => 'Request Header Fields Too Large',
73
        451 => 'Unavailable For Legal Reasons',
74
        500 => 'Internal Server Error',
75
        501 => 'Not Implemented',
76
        502 => 'Bad Gateway',
77
        503 => 'Service Unavailable',
78
        504 => 'Gateway Timeout',
79
        505 => 'HTTP Version Not Supported',
80
        506 => 'Variant Also Negotiates',
81
        507 => 'Insufficient Storage',
82
        508 => 'Loop Detected',
83
        510 => 'Not Extended',
84
        511 => 'Network Authentication Required',
85
    ];
86

87
    private $code;
88
    private $reason;
89

90
    public function __construct(int $code = 200, string $reasonPhrase = '')
91
    {
92
        $this->code = $code;
1✔
93
        $this->reason = $reasonPhrase;
1✔
94
    }
95

96
    /**
97
     * Gets the response status code.
98
     * @return int Status code.
99
     */
100
    public function getStatusCode(): int
101
    {
102
        return $this->code;
1✔
103
    }
104

105
    /**
106
     * Return an instance with the specified status code and, optionally, reason phrase.
107
     * @param int $code The 3-digit integer result code to set.
108
     * @param string $reasonPhrase The reason phrase to use.
109
     * @return static
110
     * @throws \InvalidArgumentException For invalid status code arguments.
111
     */
112
    public function withStatus(int $code, string $reasonPhrase = ''): self
113
    {
UNCOV
114
        $new = clone $this;
×
UNCOV
115
        $new->code = $code;
×
UNCOV
116
        $new->reason = $reasonPhrase;
×
UNCOV
117
        return $new;
×
118
    }
119

120
    /**
121
     * Gets the response reason phrase associated with the status code.
122
     * @return string Reason phrase; must return an empty string if none present.
123
     */
124
    public function getReasonPhrase(): string
125
    {
126
        $d = self::$codes[$this->code];
1✔
127
        return $this->reason ?: $d;
1✔
128
    }
129

130
    public function __toString(): string
131
    {
UNCOV
132
        return $this->stringable('%s', $this->getStatusCode());
×
133
    }
134

135
    public function getAsArray(): array
136
    {
UNCOV
137
        return array_merge([
×
UNCOV
138
            "HTTP/{$this->getProtocolVersion()} {$this->getStatusCode()} {$this->getReasonPhrase()}",
×
UNCOV
139
        ], parent::getAsArray());
×
140
    }
141
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc