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

sirn-se / websocket-php / 5610959835

pending completion
5610959835

push

github

Sören Jensen
Middleware support

14 of 14 new or added lines in 4 files covered. (100.0%)

283 of 676 relevant lines covered (41.86%)

1.66 hits per line

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

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

3
/**
4
 * Copyright (C) 2014-2023 Textalk and contributors.
5
 *
6
 * This file is part of Websocket PHP and is free software under the ISC License.
7
 * License text: https://raw.githubusercontent.com/sirn-se/websocket-php/master/COPYING.md
8
 */
9

10
namespace WebSocket\Http;
11

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

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

89
    private $code;
90
    private $reason;
91

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

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

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

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

132
    public function getAsArray(): array
133
    {
134
        return array_merge([
×
135
            "HTTP/{$this->getProtocolVersion()} {$this->getStatusCode()} {$this->getReasonPhrase()}",
×
136
        ], parent::getAsArray());
×
137
    }
138
}
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