Passed
Push — master ( c01d71...667403 )
by Anatoly
04:35
created
src/Uri/Component/UserInfo.php 1 patch
Indentation   +33 added lines, -33 removed lines patch added patch discarded remove patch
@@ -18,37 +18,37 @@
 block discarded – undo
18 18
  */
19 19
 final class UserInfo implements ComponentInterface
20 20
 {
21
-    private User $user;
22
-    private ?Password $password = null;
23
-
24
-    /**
25
-     * @param mixed $user
26
-     * @param mixed $password
27
-     *
28
-     * @throws InvalidArgumentException
29
-     */
30
-    public function __construct($user, $password = null)
31
-    {
32
-        $this->user = User::create($user);
33
-
34
-        if ($password !== null) {
35
-            $this->password = Password::create($password);
36
-        }
37
-    }
38
-
39
-    /**
40
-     * {@inheritdoc}
41
-     *
42
-     * @return string
43
-     */
44
-    public function getValue(): string
45
-    {
46
-        $value = $this->user->getValue();
47
-
48
-        if ($this->password !== null) {
49
-            $value .= ':' . $this->password->getValue();
50
-        }
51
-
52
-        return $value;
53
-    }
21
+	private User $user;
22
+	private ?Password $password = null;
23
+
24
+	/**
25
+	 * @param mixed $user
26
+	 * @param mixed $password
27
+	 *
28
+	 * @throws InvalidArgumentException
29
+	 */
30
+	public function __construct($user, $password = null)
31
+	{
32
+		$this->user = User::create($user);
33
+
34
+		if ($password !== null) {
35
+			$this->password = Password::create($password);
36
+		}
37
+	}
38
+
39
+	/**
40
+	 * {@inheritdoc}
41
+	 *
42
+	 * @return string
43
+	 */
44
+	public function getValue(): string
45
+	{
46
+		$value = $this->user->getValue();
47
+
48
+		if ($this->password !== null) {
49
+			$value .= ':' . $this->password->getValue();
50
+		}
51
+
52
+		return $value;
53
+	}
54 54
 }
Please login to merge, or discard this patch.
src/Uri/Component/User.php 1 patch
Indentation   +46 added lines, -46 removed lines patch added patch discarded remove patch
@@ -22,57 +22,57 @@
 block discarded – undo
22 22
  */
23 23
 final class User implements ComponentInterface
24 24
 {
25
-    // phpcs:ignore Generic.Files.LineLength
26
-    private const NORMALIZATION_REGEX = '/(?:%[0-9A-Fa-f]{2}|[\x21\x24\x26-\x2e\x30-\x39\x3b\x3d\x41-\x5a\x5f\x61-\x7a\x7e]+)|(.?)/u';
25
+	// phpcs:ignore Generic.Files.LineLength
26
+	private const NORMALIZATION_REGEX = '/(?:%[0-9A-Fa-f]{2}|[\x21\x24\x26-\x2e\x30-\x39\x3b\x3d\x41-\x5a\x5f\x61-\x7a\x7e]+)|(.?)/u';
27 27
 
28
-    private string $value = '';
28
+	private string $value = '';
29 29
 
30
-    /**
31
-     * @param mixed $value
32
-     *
33
-     * @throws InvalidArgumentException
34
-     */
35
-    public function __construct($value)
36
-    {
37
-        if ($value === '') {
38
-            return;
39
-        }
30
+	/**
31
+	 * @param mixed $value
32
+	 *
33
+	 * @throws InvalidArgumentException
34
+	 */
35
+	public function __construct($value)
36
+	{
37
+		if ($value === '') {
38
+			return;
39
+		}
40 40
 
41
-        if (!is_string($value)) {
42
-            throw new InvalidArgumentException('URI component "user" must be a string');
43
-        }
41
+		if (!is_string($value)) {
42
+			throw new InvalidArgumentException('URI component "user" must be a string');
43
+		}
44 44
 
45
-        $this->value = (string) preg_replace_callback(
46
-            self::NORMALIZATION_REGEX,
47
-            static fn(array $matches): string => (
48
-                /** @var array{0: string, 1?: string} $matches */
49
-                isset($matches[1]) ? rawurlencode($matches[1]) : $matches[0]
50
-            ),
51
-            $value,
52
-        );
53
-    }
45
+		$this->value = (string) preg_replace_callback(
46
+			self::NORMALIZATION_REGEX,
47
+			static fn(array $matches): string => (
48
+				/** @var array{0: string, 1?: string} $matches */
49
+				isset($matches[1]) ? rawurlencode($matches[1]) : $matches[0]
50
+			),
51
+			$value,
52
+		);
53
+	}
54 54
 
55
-    /**
56
-     * @param mixed $user
57
-     *
58
-     * @throws InvalidArgumentException
59
-     */
60
-    public static function create($user): User
61
-    {
62
-        if ($user instanceof User) {
63
-            return $user;
64
-        }
55
+	/**
56
+	 * @param mixed $user
57
+	 *
58
+	 * @throws InvalidArgumentException
59
+	 */
60
+	public static function create($user): User
61
+	{
62
+		if ($user instanceof User) {
63
+			return $user;
64
+		}
65 65
 
66
-        return new User($user);
67
-    }
66
+		return new User($user);
67
+	}
68 68
 
69
-    /**
70
-     * {@inheritdoc}
71
-     *
72
-     * @return string
73
-     */
74
-    public function getValue(): string
75
-    {
76
-        return $this->value;
77
-    }
69
+	/**
70
+	 * {@inheritdoc}
71
+	 *
72
+	 * @return string
73
+	 */
74
+	public function getValue(): string
75
+	{
76
+		return $this->value;
77
+	}
78 78
 }
Please login to merge, or discard this patch.
src/Uri/Component/Password.php 1 patch
Indentation   +46 added lines, -46 removed lines patch added patch discarded remove patch
@@ -22,57 +22,57 @@
 block discarded – undo
22 22
  */
23 23
 final class Password implements ComponentInterface
24 24
 {
25
-    // phpcs:ignore Generic.Files.LineLength
26
-    private const NORMALIZATION_REGEX = '/(?:%[0-9A-Fa-f]{2}|[\x21\x24\x26-\x2e\x30-\x39\x3b\x3d\x41-\x5a\x5f\x61-\x7a\x7e]+)|(.?)/u';
25
+	// phpcs:ignore Generic.Files.LineLength
26
+	private const NORMALIZATION_REGEX = '/(?:%[0-9A-Fa-f]{2}|[\x21\x24\x26-\x2e\x30-\x39\x3b\x3d\x41-\x5a\x5f\x61-\x7a\x7e]+)|(.?)/u';
27 27
 
28
-    private string $value = '';
28
+	private string $value = '';
29 29
 
30
-    /**
31
-     * @param mixed $value
32
-     *
33
-     * @throws InvalidArgumentException
34
-     */
35
-    public function __construct($value)
36
-    {
37
-        if ($value === '') {
38
-            return;
39
-        }
30
+	/**
31
+	 * @param mixed $value
32
+	 *
33
+	 * @throws InvalidArgumentException
34
+	 */
35
+	public function __construct($value)
36
+	{
37
+		if ($value === '') {
38
+			return;
39
+		}
40 40
 
41
-        if (!is_string($value)) {
42
-            throw new InvalidArgumentException('URI component "password" must be a string');
43
-        }
41
+		if (!is_string($value)) {
42
+			throw new InvalidArgumentException('URI component "password" must be a string');
43
+		}
44 44
 
45
-        $this->value = (string) preg_replace_callback(
46
-            self::NORMALIZATION_REGEX,
47
-            static fn(array $matches): string => (
48
-                /** @var array{0: string, 1?: string} $matches */
49
-                isset($matches[1]) ? rawurlencode($matches[1]) : $matches[0]
50
-            ),
51
-            $value,
52
-        );
53
-    }
45
+		$this->value = (string) preg_replace_callback(
46
+			self::NORMALIZATION_REGEX,
47
+			static fn(array $matches): string => (
48
+				/** @var array{0: string, 1?: string} $matches */
49
+				isset($matches[1]) ? rawurlencode($matches[1]) : $matches[0]
50
+			),
51
+			$value,
52
+		);
53
+	}
54 54
 
55
-    /**
56
-     * @param mixed $password
57
-     *
58
-     * @throws InvalidArgumentException
59
-     */
60
-    public static function create($password): Password
61
-    {
62
-        if ($password instanceof Password) {
63
-            return $password;
64
-        }
55
+	/**
56
+	 * @param mixed $password
57
+	 *
58
+	 * @throws InvalidArgumentException
59
+	 */
60
+	public static function create($password): Password
61
+	{
62
+		if ($password instanceof Password) {
63
+			return $password;
64
+		}
65 65
 
66
-        return new Password($password);
67
-    }
66
+		return new Password($password);
67
+	}
68 68
 
69
-    /**
70
-     * {@inheritdoc}
71
-     *
72
-     * @return string
73
-     */
74
-    public function getValue(): string
75
-    {
76
-        return $this->value;
77
-    }
69
+	/**
70
+	 * {@inheritdoc}
71
+	 *
72
+	 * @return string
73
+	 */
74
+	public function getValue(): string
75
+	{
76
+		return $this->value;
77
+	}
78 78
 }
Please login to merge, or discard this patch.
src/Uri/Component/Path.php 1 patch
Indentation   +34 added lines, -34 removed lines patch added patch discarded remove patch
@@ -22,43 +22,43 @@
 block discarded – undo
22 22
  */
23 23
 final class Path implements ComponentInterface
24 24
 {
25
-    // phpcs:ignore Generic.Files.LineLength
26
-    private const NORMALIZATION_REGEX = '/(?:%[0-9A-Fa-f]{2}|[\x21\x24\x26-\x3b\x3d\x40-\x5a\x5f\x61-\x7a\x7e]+)|(.?)/u';
25
+	// phpcs:ignore Generic.Files.LineLength
26
+	private const NORMALIZATION_REGEX = '/(?:%[0-9A-Fa-f]{2}|[\x21\x24\x26-\x3b\x3d\x40-\x5a\x5f\x61-\x7a\x7e]+)|(.?)/u';
27 27
 
28
-    private string $value = '';
28
+	private string $value = '';
29 29
 
30
-    /**
31
-     * @param mixed $value
32
-     *
33
-     * @throws InvalidArgumentException
34
-     */
35
-    public function __construct($value)
36
-    {
37
-        if ($value === '') {
38
-            return;
39
-        }
30
+	/**
31
+	 * @param mixed $value
32
+	 *
33
+	 * @throws InvalidArgumentException
34
+	 */
35
+	public function __construct($value)
36
+	{
37
+		if ($value === '') {
38
+			return;
39
+		}
40 40
 
41
-        if (!is_string($value)) {
42
-            throw new InvalidArgumentException('URI component "path" must be a string');
43
-        }
41
+		if (!is_string($value)) {
42
+			throw new InvalidArgumentException('URI component "path" must be a string');
43
+		}
44 44
 
45
-        $this->value = (string) preg_replace_callback(
46
-            self::NORMALIZATION_REGEX,
47
-            static fn(array $matches): string => (
48
-                /** @var array{0: string, 1?: string} $matches */
49
-                isset($matches[1]) ? rawurlencode($matches[1]) : $matches[0]
50
-            ),
51
-            $value,
52
-        );
53
-    }
45
+		$this->value = (string) preg_replace_callback(
46
+			self::NORMALIZATION_REGEX,
47
+			static fn(array $matches): string => (
48
+				/** @var array{0: string, 1?: string} $matches */
49
+				isset($matches[1]) ? rawurlencode($matches[1]) : $matches[0]
50
+			),
51
+			$value,
52
+		);
53
+	}
54 54
 
55
-    /**
56
-     * {@inheritdoc}
57
-     *
58
-     * @return string
59
-     */
60
-    public function getValue(): string
61
-    {
62
-        return $this->value;
63
-    }
55
+	/**
56
+	 * {@inheritdoc}
57
+	 *
58
+	 * @return string
59
+	 */
60
+	public function getValue(): string
61
+	{
62
+		return $this->value;
63
+	}
64 64
 }
Please login to merge, or discard this patch.
src/Uri/Component/ComponentInterface.php 1 patch
Indentation   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -13,8 +13,8 @@
 block discarded – undo
13 13
 
14 14
 interface ComponentInterface
15 15
 {
16
-    /**
17
-     * @return mixed
18
-     */
19
-    public function getValue();
16
+	/**
17
+	 * @return mixed
18
+	 */
19
+	public function getValue();
20 20
 }
Please login to merge, or discard this patch.
src/Uri/Component/Host.php 1 patch
Indentation   +36 added lines, -36 removed lines patch added patch discarded remove patch
@@ -23,46 +23,46 @@
 block discarded – undo
23 23
  */
24 24
 final class Host implements ComponentInterface
25 25
 {
26
-    // phpcs:ignore Generic.Files.LineLength
27
-    private const NORMALIZATION_REGEX = '/(?:%[0-9A-Fa-f]{2}|[\x21\x24\x26-\x2e\x30-\x39\x3b\x3d\x41-\x5a\x5f\x61-\x7a\x7e]+)|(.?)/u';
26
+	// phpcs:ignore Generic.Files.LineLength
27
+	private const NORMALIZATION_REGEX = '/(?:%[0-9A-Fa-f]{2}|[\x21\x24\x26-\x2e\x30-\x39\x3b\x3d\x41-\x5a\x5f\x61-\x7a\x7e]+)|(.?)/u';
28 28
 
29
-    private string $value = '';
29
+	private string $value = '';
30 30
 
31
-    /**
32
-     * @param mixed $value
33
-     *
34
-     * @throws InvalidArgumentException
35
-     */
36
-    public function __construct($value)
37
-    {
38
-        if ($value === '') {
39
-            return;
40
-        }
31
+	/**
32
+	 * @param mixed $value
33
+	 *
34
+	 * @throws InvalidArgumentException
35
+	 */
36
+	public function __construct($value)
37
+	{
38
+		if ($value === '') {
39
+			return;
40
+		}
41 41
 
42
-        if (!is_string($value)) {
43
-            throw new InvalidArgumentException('URI component "host" must be a string');
44
-        }
42
+		if (!is_string($value)) {
43
+			throw new InvalidArgumentException('URI component "host" must be a string');
44
+		}
45 45
 
46
-        $this->value = (string) preg_replace_callback(
47
-            self::NORMALIZATION_REGEX,
48
-            static fn(array $matches): string => (
49
-                /** @var array{0: string, 1?: string} $matches */
50
-                isset($matches[1]) ? rawurlencode($matches[1]) : $matches[0]
51
-            ),
52
-            $value,
53
-        );
46
+		$this->value = (string) preg_replace_callback(
47
+			self::NORMALIZATION_REGEX,
48
+			static fn(array $matches): string => (
49
+				/** @var array{0: string, 1?: string} $matches */
50
+				isset($matches[1]) ? rawurlencode($matches[1]) : $matches[0]
51
+			),
52
+			$value,
53
+		);
54 54
 
55
-        // the component is case-insensitive...
56
-        $this->value = strtolower($this->value);
57
-    }
55
+		// the component is case-insensitive...
56
+		$this->value = strtolower($this->value);
57
+	}
58 58
 
59
-    /**
60
-     * {@inheritdoc}
61
-     *
62
-     * @return string
63
-     */
64
-    public function getValue(): string
65
-    {
66
-        return $this->value;
67
-    }
59
+	/**
60
+	 * {@inheritdoc}
61
+	 *
62
+	 * @return string
63
+	 */
64
+	public function getValue(): string
65
+	{
66
+		return $this->value;
67
+	}
68 68
 }
Please login to merge, or discard this patch.
src/Uri/Component/Scheme.php 1 patch
Indentation   +36 added lines, -36 removed lines patch added patch discarded remove patch
@@ -22,40 +22,40 @@
 block discarded – undo
22 22
  */
23 23
 final class Scheme implements ComponentInterface
24 24
 {
25
-    private const VALIDATION_REGEX = '/^(?:[A-Za-z][0-9A-Za-z\x2b\x2d\x2e]*)?$/';
26
-
27
-    private string $value = '';
28
-
29
-    /**
30
-     * @param mixed $value
31
-     *
32
-     * @throws InvalidArgumentException
33
-     */
34
-    public function __construct($value)
35
-    {
36
-        if ($value === '') {
37
-            return;
38
-        }
39
-
40
-        if (!is_string($value)) {
41
-            throw new InvalidArgumentException('URI component "scheme" must be a string');
42
-        }
43
-
44
-        if (!preg_match(self::VALIDATION_REGEX, $value)) {
45
-            throw new InvalidArgumentException('Invalid URI component "scheme"');
46
-        }
47
-
48
-        // the component is case-insensitive...
49
-        $this->value = strtolower($value);
50
-    }
51
-
52
-    /**
53
-     * {@inheritdoc}
54
-     *
55
-     * @return string
56
-     */
57
-    public function getValue(): string
58
-    {
59
-        return $this->value;
60
-    }
25
+	private const VALIDATION_REGEX = '/^(?:[A-Za-z][0-9A-Za-z\x2b\x2d\x2e]*)?$/';
26
+
27
+	private string $value = '';
28
+
29
+	/**
30
+	 * @param mixed $value
31
+	 *
32
+	 * @throws InvalidArgumentException
33
+	 */
34
+	public function __construct($value)
35
+	{
36
+		if ($value === '') {
37
+			return;
38
+		}
39
+
40
+		if (!is_string($value)) {
41
+			throw new InvalidArgumentException('URI component "scheme" must be a string');
42
+		}
43
+
44
+		if (!preg_match(self::VALIDATION_REGEX, $value)) {
45
+			throw new InvalidArgumentException('Invalid URI component "scheme"');
46
+		}
47
+
48
+		// the component is case-insensitive...
49
+		$this->value = strtolower($value);
50
+	}
51
+
52
+	/**
53
+	 * {@inheritdoc}
54
+	 *
55
+	 * @return string
56
+	 */
57
+	public function getValue(): string
58
+	{
59
+		return $this->value;
60
+	}
61 61
 }
Please login to merge, or discard this patch.
src/HeaderInterface.php 1 patch
Indentation   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -18,17 +18,17 @@
 block discarded – undo
18 18
  */
19 19
 interface HeaderInterface extends IteratorAggregate
20 20
 {
21
-    public const RFC822_DATE_FORMAT = 'D, d M y H:i:s O';
21
+	public const RFC822_DATE_FORMAT = 'D, d M y H:i:s O';
22 22
 
23
-    public const RFC7230_TOKEN_REGEX = '/^[\x21\x23-\x27\x2A\x2B\x2D\x2E\x30-\x39\x41-\x5A\x5E-\x7A\x7C\x7E]+$/';
23
+	public const RFC7230_TOKEN_REGEX = '/^[\x21\x23-\x27\x2A\x2B\x2D\x2E\x30-\x39\x41-\x5A\x5E-\x7A\x7C\x7E]+$/';
24 24
 
25
-    public const RFC7230_FIELD_VALUE_REGEX = '/^[\x09\x20-\x7E\x80-\xFF]*$/';
25
+	public const RFC7230_FIELD_VALUE_REGEX = '/^[\x09\x20-\x7E\x80-\xFF]*$/';
26 26
 
27
-    public const RFC7230_QUOTED_STRING_REGEX = '/^(?:[\x5C][\x22]|[\x09\x20\x21\x23-\x5B\x5D-\x7E\x80-\xFF])*$/';
27
+	public const RFC7230_QUOTED_STRING_REGEX = '/^(?:[\x5C][\x22]|[\x09\x20\x21\x23-\x5B\x5D-\x7E\x80-\xFF])*$/';
28 28
 
29
-    public function getFieldName(): string;
29
+	public function getFieldName(): string;
30 30
 
31
-    public function getFieldValue(): string;
31
+	public function getFieldValue(): string;
32 32
 
33
-    public function __toString(): string;
33
+	public function __toString(): string;
34 34
 }
Please login to merge, or discard this patch.
src/Response.php 1 patch
Indentation   +194 added lines, -194 removed lines patch added patch discarded remove patch
@@ -22,198 +22,198 @@
 block discarded – undo
22 22
 
23 23
 class Response extends Message implements ResponseInterface, StatusCodeInterface
24 24
 {
25
-    /**
26
-     * List of Reason Phrases
27
-     *
28
-     * @link http://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml
29
-     *
30
-     * @var array<int<100, 599>, non-empty-string>
31
-     */
32
-    public const REASON_PHRASES = [
33
-        // 1xx
34
-        100 => 'Continue',
35
-        101 => 'Switching Protocols',
36
-        102 => 'Processing',
37
-        103 => 'Early Hints',
38
-        // 2xx
39
-        200 => 'OK',
40
-        201 => 'Created',
41
-        202 => 'Accepted',
42
-        203 => 'Non-Authoritative Information',
43
-        204 => 'No Content',
44
-        205 => 'Reset Content',
45
-        206 => 'Partial Content',
46
-        207 => 'Multi-Status',
47
-        208 => 'Already Reported',
48
-        226 => 'IM Used',
49
-        // 3xx
50
-        300 => 'Multiple Choices',
51
-        301 => 'Moved Permanently',
52
-        302 => 'Found',
53
-        303 => 'See Other',
54
-        304 => 'Not Modified',
55
-        305 => 'Use Proxy',
56
-        307 => 'Temporary Redirect',
57
-        308 => 'Permanent Redirect',
58
-        // 4xx
59
-        400 => 'Bad Request',
60
-        401 => 'Unauthorized',
61
-        402 => 'Payment Required',
62
-        403 => 'Forbidden',
63
-        404 => 'Not Found',
64
-        405 => 'Method Not Allowed',
65
-        406 => 'Not Acceptable',
66
-        407 => 'Proxy Authentication Required',
67
-        408 => 'Request Timeout',
68
-        409 => 'Conflict',
69
-        410 => 'Gone',
70
-        411 => 'Length Required',
71
-        412 => 'Precondition Failed',
72
-        413 => 'Payload Too Large',
73
-        414 => 'URI Too Long',
74
-        415 => 'Unsupported Media Type',
75
-        416 => 'Range Not Satisfiable',
76
-        417 => 'Expectation Failed',
77
-        421 => 'Misdirected Request',
78
-        422 => 'Unprocessable Entity',
79
-        423 => 'Locked',
80
-        424 => 'Failed Dependency',
81
-        425 => 'Too Early',
82
-        426 => 'Upgrade Required',
83
-        428 => 'Precondition Required',
84
-        429 => 'Too Many Requests',
85
-        431 => 'Request Header Fields Too Large',
86
-        451 => 'Unavailable For Legal Reasons',
87
-        // 5xx
88
-        500 => 'Internal Server Error',
89
-        501 => 'Not Implemented',
90
-        502 => 'Bad Gateway',
91
-        503 => 'Service Unavailable',
92
-        504 => 'Gateway Timeout',
93
-        505 => 'HTTP Version Not Supported',
94
-        506 => 'Variant Also Negotiates',
95
-        507 => 'Insufficient Storage',
96
-        508 => 'Loop Detected',
97
-        510 => 'Not Extended',
98
-        511 => 'Network Authentication Required',
99
-    ];
100
-
101
-    private int $statusCode = self::STATUS_OK;
102
-    private string $reasonPhrase = self::REASON_PHRASES[self::STATUS_OK];
103
-
104
-    /**
105
-     * @param array<string, string|string[]>|null $headers
106
-     *
107
-     * @throws InvalidArgumentException
108
-     */
109
-    public function __construct(
110
-        ?int $statusCode = null,
111
-        ?string $reasonPhrase = null,
112
-        ?array $headers = null,
113
-        ?StreamInterface $body = null
114
-    ) {
115
-        if ($statusCode !== null) {
116
-            $this->setStatus($statusCode, $reasonPhrase ?? '');
117
-        }
118
-
119
-        if ($headers !== null) {
120
-            $this->setHeaders($headers);
121
-        }
122
-
123
-        if ($body !== null) {
124
-            $this->setBody($body);
125
-        }
126
-    }
127
-
128
-    /**
129
-     * @inheritDoc
130
-     */
131
-    public function getStatusCode(): int
132
-    {
133
-        return $this->statusCode;
134
-    }
135
-
136
-    /**
137
-     * @inheritDoc
138
-     */
139
-    public function getReasonPhrase(): string
140
-    {
141
-        return $this->reasonPhrase;
142
-    }
143
-
144
-    /**
145
-     * @inheritDoc
146
-     */
147
-    public function withStatus($code, $reasonPhrase = ''): ResponseInterface
148
-    {
149
-        $clone = clone $this;
150
-        $clone->setStatus($code, $reasonPhrase);
151
-
152
-        return $clone;
153
-    }
154
-
155
-    /**
156
-     * Sets the given status code to the response
157
-     *
158
-     * @param int $statusCode
159
-     * @param string $reasonPhrase
160
-     *
161
-     * @throws InvalidArgumentException
162
-     */
163
-    final protected function setStatus($statusCode, $reasonPhrase): void
164
-    {
165
-        $this->validateStatusCode($statusCode);
166
-        $this->validateReasonPhrase($reasonPhrase);
167
-
168
-        if ($reasonPhrase === '') {
169
-            $reasonPhrase = self::REASON_PHRASES[$statusCode] ?? 'Unknown Status Code';
170
-        }
171
-
172
-        $this->statusCode = $statusCode;
173
-        $this->reasonPhrase = $reasonPhrase;
174
-    }
175
-
176
-    /**
177
-     * Validates the given status code
178
-     *
179
-     * @link https://tools.ietf.org/html/rfc7230#section-3.1.2
180
-     *
181
-     * @param mixed $statusCode
182
-     *
183
-     * @throws InvalidArgumentException
184
-     */
185
-    private function validateStatusCode($statusCode): void
186
-    {
187
-        if (!is_int($statusCode)) {
188
-            throw new InvalidArgumentException('HTTP status code must be an integer');
189
-        }
190
-
191
-        if (!($statusCode >= 100 && $statusCode <= 599)) {
192
-            throw new InvalidArgumentException('Invalid HTTP status code');
193
-        }
194
-    }
195
-
196
-    /**
197
-     * Validates the given reason phrase
198
-     *
199
-     * @link https://tools.ietf.org/html/rfc7230#section-3.1.2
200
-     *
201
-     * @param mixed $reasonPhrase
202
-     *
203
-     * @throws InvalidArgumentException
204
-     */
205
-    private function validateReasonPhrase($reasonPhrase): void
206
-    {
207
-        if ($reasonPhrase === '') {
208
-            return;
209
-        }
210
-
211
-        if (!is_string($reasonPhrase)) {
212
-            throw new InvalidArgumentException('HTTP reason phrase must be a string');
213
-        }
214
-
215
-        if (!preg_match(HeaderInterface::RFC7230_FIELD_VALUE_REGEX, $reasonPhrase)) {
216
-            throw new InvalidArgumentException('Invalid HTTP reason phrase');
217
-        }
218
-    }
25
+	/**
26
+	 * List of Reason Phrases
27
+	 *
28
+	 * @link http://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml
29
+	 *
30
+	 * @var array<int<100, 599>, non-empty-string>
31
+	 */
32
+	public const REASON_PHRASES = [
33
+		// 1xx
34
+		100 => 'Continue',
35
+		101 => 'Switching Protocols',
36
+		102 => 'Processing',
37
+		103 => 'Early Hints',
38
+		// 2xx
39
+		200 => 'OK',
40
+		201 => 'Created',
41
+		202 => 'Accepted',
42
+		203 => 'Non-Authoritative Information',
43
+		204 => 'No Content',
44
+		205 => 'Reset Content',
45
+		206 => 'Partial Content',
46
+		207 => 'Multi-Status',
47
+		208 => 'Already Reported',
48
+		226 => 'IM Used',
49
+		// 3xx
50
+		300 => 'Multiple Choices',
51
+		301 => 'Moved Permanently',
52
+		302 => 'Found',
53
+		303 => 'See Other',
54
+		304 => 'Not Modified',
55
+		305 => 'Use Proxy',
56
+		307 => 'Temporary Redirect',
57
+		308 => 'Permanent Redirect',
58
+		// 4xx
59
+		400 => 'Bad Request',
60
+		401 => 'Unauthorized',
61
+		402 => 'Payment Required',
62
+		403 => 'Forbidden',
63
+		404 => 'Not Found',
64
+		405 => 'Method Not Allowed',
65
+		406 => 'Not Acceptable',
66
+		407 => 'Proxy Authentication Required',
67
+		408 => 'Request Timeout',
68
+		409 => 'Conflict',
69
+		410 => 'Gone',
70
+		411 => 'Length Required',
71
+		412 => 'Precondition Failed',
72
+		413 => 'Payload Too Large',
73
+		414 => 'URI Too Long',
74
+		415 => 'Unsupported Media Type',
75
+		416 => 'Range Not Satisfiable',
76
+		417 => 'Expectation Failed',
77
+		421 => 'Misdirected Request',
78
+		422 => 'Unprocessable Entity',
79
+		423 => 'Locked',
80
+		424 => 'Failed Dependency',
81
+		425 => 'Too Early',
82
+		426 => 'Upgrade Required',
83
+		428 => 'Precondition Required',
84
+		429 => 'Too Many Requests',
85
+		431 => 'Request Header Fields Too Large',
86
+		451 => 'Unavailable For Legal Reasons',
87
+		// 5xx
88
+		500 => 'Internal Server Error',
89
+		501 => 'Not Implemented',
90
+		502 => 'Bad Gateway',
91
+		503 => 'Service Unavailable',
92
+		504 => 'Gateway Timeout',
93
+		505 => 'HTTP Version Not Supported',
94
+		506 => 'Variant Also Negotiates',
95
+		507 => 'Insufficient Storage',
96
+		508 => 'Loop Detected',
97
+		510 => 'Not Extended',
98
+		511 => 'Network Authentication Required',
99
+	];
100
+
101
+	private int $statusCode = self::STATUS_OK;
102
+	private string $reasonPhrase = self::REASON_PHRASES[self::STATUS_OK];
103
+
104
+	/**
105
+	 * @param array<string, string|string[]>|null $headers
106
+	 *
107
+	 * @throws InvalidArgumentException
108
+	 */
109
+	public function __construct(
110
+		?int $statusCode = null,
111
+		?string $reasonPhrase = null,
112
+		?array $headers = null,
113
+		?StreamInterface $body = null
114
+	) {
115
+		if ($statusCode !== null) {
116
+			$this->setStatus($statusCode, $reasonPhrase ?? '');
117
+		}
118
+
119
+		if ($headers !== null) {
120
+			$this->setHeaders($headers);
121
+		}
122
+
123
+		if ($body !== null) {
124
+			$this->setBody($body);
125
+		}
126
+	}
127
+
128
+	/**
129
+	 * @inheritDoc
130
+	 */
131
+	public function getStatusCode(): int
132
+	{
133
+		return $this->statusCode;
134
+	}
135
+
136
+	/**
137
+	 * @inheritDoc
138
+	 */
139
+	public function getReasonPhrase(): string
140
+	{
141
+		return $this->reasonPhrase;
142
+	}
143
+
144
+	/**
145
+	 * @inheritDoc
146
+	 */
147
+	public function withStatus($code, $reasonPhrase = ''): ResponseInterface
148
+	{
149
+		$clone = clone $this;
150
+		$clone->setStatus($code, $reasonPhrase);
151
+
152
+		return $clone;
153
+	}
154
+
155
+	/**
156
+	 * Sets the given status code to the response
157
+	 *
158
+	 * @param int $statusCode
159
+	 * @param string $reasonPhrase
160
+	 *
161
+	 * @throws InvalidArgumentException
162
+	 */
163
+	final protected function setStatus($statusCode, $reasonPhrase): void
164
+	{
165
+		$this->validateStatusCode($statusCode);
166
+		$this->validateReasonPhrase($reasonPhrase);
167
+
168
+		if ($reasonPhrase === '') {
169
+			$reasonPhrase = self::REASON_PHRASES[$statusCode] ?? 'Unknown Status Code';
170
+		}
171
+
172
+		$this->statusCode = $statusCode;
173
+		$this->reasonPhrase = $reasonPhrase;
174
+	}
175
+
176
+	/**
177
+	 * Validates the given status code
178
+	 *
179
+	 * @link https://tools.ietf.org/html/rfc7230#section-3.1.2
180
+	 *
181
+	 * @param mixed $statusCode
182
+	 *
183
+	 * @throws InvalidArgumentException
184
+	 */
185
+	private function validateStatusCode($statusCode): void
186
+	{
187
+		if (!is_int($statusCode)) {
188
+			throw new InvalidArgumentException('HTTP status code must be an integer');
189
+		}
190
+
191
+		if (!($statusCode >= 100 && $statusCode <= 599)) {
192
+			throw new InvalidArgumentException('Invalid HTTP status code');
193
+		}
194
+	}
195
+
196
+	/**
197
+	 * Validates the given reason phrase
198
+	 *
199
+	 * @link https://tools.ietf.org/html/rfc7230#section-3.1.2
200
+	 *
201
+	 * @param mixed $reasonPhrase
202
+	 *
203
+	 * @throws InvalidArgumentException
204
+	 */
205
+	private function validateReasonPhrase($reasonPhrase): void
206
+	{
207
+		if ($reasonPhrase === '') {
208
+			return;
209
+		}
210
+
211
+		if (!is_string($reasonPhrase)) {
212
+			throw new InvalidArgumentException('HTTP reason phrase must be a string');
213
+		}
214
+
215
+		if (!preg_match(HeaderInterface::RFC7230_FIELD_VALUE_REGEX, $reasonPhrase)) {
216
+			throw new InvalidArgumentException('Invalid HTTP reason phrase');
217
+		}
218
+	}
219 219
 }
Please login to merge, or discard this patch.