Passed
Pull Request — master (#31)
by Anatoly
39:30
created
src/Header/WarningHeader.php 2 patches
Indentation   +120 added lines, -120 removed lines patch added patch discarded remove patch
@@ -30,124 +30,124 @@
 block discarded – undo
30 30
 class WarningHeader extends Header
31 31
 {
32 32
 
33
-    /**
34
-     * @deprecated Use the {@see WarningCode} enum.
35
-     */
36
-    public const HTTP_WARNING_CODE_RESPONSE_IS_STALE = WarningCode::RESPONSE_IS_STALE;
37
-
38
-    /**
39
-     * @deprecated Use the {@see WarningCode} enum.
40
-     */
41
-    public const HTTP_WARNING_CODE_REVALIDATION_FAILED = WarningCode::REVALIDATION_FAILED;
42
-
43
-    /**
44
-     * @deprecated Use the {@see WarningCode} enum.
45
-     */
46
-    public const HTTP_WARNING_CODE_DISCONNECTED_OPERATION = WarningCode::DISCONNECTED_OPERATION;
47
-
48
-    /**
49
-     * @deprecated Use the {@see WarningCode} enum.
50
-     */
51
-    public const HTTP_WARNING_CODE_HEURISTIC_EXPIRATION = WarningCode::HEURISTIC_EXPIRATION;
52
-
53
-    /**
54
-     * @deprecated Use the {@see WarningCode} enum.
55
-     */
56
-    public const HTTP_WARNING_CODE_MISCELLANEOUS_WARNING = WarningCode::MISCELLANEOUS_WARNING;
57
-
58
-    /**
59
-     * @deprecated Use the {@see WarningCode} enum.
60
-     */
61
-    public const HTTP_WARNING_CODE_TRANSFORMATION_APPLIED = WarningCode::TRANSFORMATION_APPLIED;
62
-
63
-    /**
64
-     * @deprecated Use the {@see WarningCode} enum.
65
-     */
66
-    public const HTTP_WARNING_CODE_MISCELLANEOUS_PERSISTENT_WARNING = WarningCode::MISCELLANEOUS_PERSISTENT_WARNING;
67
-
68
-    /**
69
-     * @var int
70
-     */
71
-    private int $code;
72
-
73
-    /**
74
-     * @var string
75
-     */
76
-    private string $agent;
77
-
78
-    /**
79
-     * @var string
80
-     */
81
-    private string $text;
82
-
83
-    /**
84
-     * @var DateTimeInterface|null
85
-     */
86
-    private ?DateTimeInterface $date;
87
-
88
-    /**
89
-     * Constructor of the class
90
-     *
91
-     * @param int $code
92
-     * @param string $agent
93
-     * @param string $text
94
-     * @param DateTimeInterface|null $date
95
-     *
96
-     * @throws InvalidHeaderException
97
-     *         If one of arguments isn't valid.
98
-     */
99
-    public function __construct(int $code, string $agent, string $text, ?DateTimeInterface $date = null)
100
-    {
101
-        $this->validateCode($code);
102
-        $this->validateToken($agent);
103
-        $this->validateQuotedString($text);
104
-
105
-        $this->code = $code;
106
-        $this->agent = $agent;
107
-        $this->text = $text;
108
-        $this->date = $date;
109
-    }
110
-
111
-    /**
112
-     * {@inheritdoc}
113
-     */
114
-    public function getFieldName(): string
115
-    {
116
-        return 'Warning';
117
-    }
118
-
119
-    /**
120
-     * {@inheritdoc}
121
-     */
122
-    public function getFieldValue(): string
123
-    {
124
-        $value = sprintf('%s %s "%s"', $this->code, $this->agent, $this->text);
125
-
126
-        if (isset($this->date)) {
127
-            $value .= sprintf(' "%s"', $this->formatDateTime($this->date));
128
-        }
129
-
130
-        return $value;
131
-    }
132
-
133
-    /**
134
-     * Validates the given code
135
-     *
136
-     * @param int $code
137
-     *
138
-     * @return void
139
-     *
140
-     * @throws InvalidHeaderException
141
-     *         If the code isn't valid.
142
-     */
143
-    private function validateCode(int $code): void
144
-    {
145
-        if (! ($code >= 100 && $code <= 999)) {
146
-            throw new InvalidHeaderException(sprintf(
147
-                'The code "%2$d" for the header "%1$s" is not valid',
148
-                $this->getFieldName(),
149
-                $code
150
-            ));
151
-        }
152
-    }
33
+	/**
34
+	 * @deprecated Use the {@see WarningCode} enum.
35
+	 */
36
+	public const HTTP_WARNING_CODE_RESPONSE_IS_STALE = WarningCode::RESPONSE_IS_STALE;
37
+
38
+	/**
39
+	 * @deprecated Use the {@see WarningCode} enum.
40
+	 */
41
+	public const HTTP_WARNING_CODE_REVALIDATION_FAILED = WarningCode::REVALIDATION_FAILED;
42
+
43
+	/**
44
+	 * @deprecated Use the {@see WarningCode} enum.
45
+	 */
46
+	public const HTTP_WARNING_CODE_DISCONNECTED_OPERATION = WarningCode::DISCONNECTED_OPERATION;
47
+
48
+	/**
49
+	 * @deprecated Use the {@see WarningCode} enum.
50
+	 */
51
+	public const HTTP_WARNING_CODE_HEURISTIC_EXPIRATION = WarningCode::HEURISTIC_EXPIRATION;
52
+
53
+	/**
54
+	 * @deprecated Use the {@see WarningCode} enum.
55
+	 */
56
+	public const HTTP_WARNING_CODE_MISCELLANEOUS_WARNING = WarningCode::MISCELLANEOUS_WARNING;
57
+
58
+	/**
59
+	 * @deprecated Use the {@see WarningCode} enum.
60
+	 */
61
+	public const HTTP_WARNING_CODE_TRANSFORMATION_APPLIED = WarningCode::TRANSFORMATION_APPLIED;
62
+
63
+	/**
64
+	 * @deprecated Use the {@see WarningCode} enum.
65
+	 */
66
+	public const HTTP_WARNING_CODE_MISCELLANEOUS_PERSISTENT_WARNING = WarningCode::MISCELLANEOUS_PERSISTENT_WARNING;
67
+
68
+	/**
69
+	 * @var int
70
+	 */
71
+	private int $code;
72
+
73
+	/**
74
+	 * @var string
75
+	 */
76
+	private string $agent;
77
+
78
+	/**
79
+	 * @var string
80
+	 */
81
+	private string $text;
82
+
83
+	/**
84
+	 * @var DateTimeInterface|null
85
+	 */
86
+	private ?DateTimeInterface $date;
87
+
88
+	/**
89
+	 * Constructor of the class
90
+	 *
91
+	 * @param int $code
92
+	 * @param string $agent
93
+	 * @param string $text
94
+	 * @param DateTimeInterface|null $date
95
+	 *
96
+	 * @throws InvalidHeaderException
97
+	 *         If one of arguments isn't valid.
98
+	 */
99
+	public function __construct(int $code, string $agent, string $text, ?DateTimeInterface $date = null)
100
+	{
101
+		$this->validateCode($code);
102
+		$this->validateToken($agent);
103
+		$this->validateQuotedString($text);
104
+
105
+		$this->code = $code;
106
+		$this->agent = $agent;
107
+		$this->text = $text;
108
+		$this->date = $date;
109
+	}
110
+
111
+	/**
112
+	 * {@inheritdoc}
113
+	 */
114
+	public function getFieldName(): string
115
+	{
116
+		return 'Warning';
117
+	}
118
+
119
+	/**
120
+	 * {@inheritdoc}
121
+	 */
122
+	public function getFieldValue(): string
123
+	{
124
+		$value = sprintf('%s %s "%s"', $this->code, $this->agent, $this->text);
125
+
126
+		if (isset($this->date)) {
127
+			$value .= sprintf(' "%s"', $this->formatDateTime($this->date));
128
+		}
129
+
130
+		return $value;
131
+	}
132
+
133
+	/**
134
+	 * Validates the given code
135
+	 *
136
+	 * @param int $code
137
+	 *
138
+	 * @return void
139
+	 *
140
+	 * @throws InvalidHeaderException
141
+	 *         If the code isn't valid.
142
+	 */
143
+	private function validateCode(int $code): void
144
+	{
145
+		if (! ($code >= 100 && $code <= 999)) {
146
+			throw new InvalidHeaderException(sprintf(
147
+				'The code "%2$d" for the header "%1$s" is not valid',
148
+				$this->getFieldName(),
149
+				$code
150
+			));
151
+		}
152
+	}
153 153
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -142,7 +142,7 @@
 block discarded – undo
142 142
      */
143 143
     private function validateCode(int $code): void
144 144
     {
145
-        if (! ($code >= 100 && $code <= 999)) {
145
+        if (!($code >= 100 && $code <= 999)) {
146 146
             throw new InvalidHeaderException(sprintf(
147 147
                 'The code "%2$d" for the header "%1$s" is not valid',
148 148
                 $this->getFieldName(),
Please login to merge, or discard this patch.
src/Header/AllowHeader.php 1 patch
Indentation   +33 added lines, -33 removed lines patch added patch discarded remove patch
@@ -29,41 +29,41 @@
 block discarded – undo
29 29
 class AllowHeader extends Header
30 30
 {
31 31
 
32
-    /**
33
-     * @var list<string>
34
-     */
35
-    private array $methods = [];
32
+	/**
33
+	 * @var list<string>
34
+	 */
35
+	private array $methods = [];
36 36
 
37
-    /**
38
-     * Constructor of the class
39
-     *
40
-     * @param string ...$methods
41
-     *
42
-     * @throws InvalidHeaderException
43
-     *         If one of the methods isn't valid.
44
-     */
45
-    public function __construct(string ...$methods)
46
-    {
47
-        $this->validateToken(...$methods);
37
+	/**
38
+	 * Constructor of the class
39
+	 *
40
+	 * @param string ...$methods
41
+	 *
42
+	 * @throws InvalidHeaderException
43
+	 *         If one of the methods isn't valid.
44
+	 */
45
+	public function __construct(string ...$methods)
46
+	{
47
+		$this->validateToken(...$methods);
48 48
 
49
-        foreach ($methods as $method) {
50
-            $this->methods[] = strtoupper($method);
51
-        }
52
-    }
49
+		foreach ($methods as $method) {
50
+			$this->methods[] = strtoupper($method);
51
+		}
52
+	}
53 53
 
54
-    /**
55
-     * {@inheritdoc}
56
-     */
57
-    public function getFieldName(): string
58
-    {
59
-        return 'Allow';
60
-    }
54
+	/**
55
+	 * {@inheritdoc}
56
+	 */
57
+	public function getFieldName(): string
58
+	{
59
+		return 'Allow';
60
+	}
61 61
 
62
-    /**
63
-     * {@inheritdoc}
64
-     */
65
-    public function getFieldValue(): string
66
-    {
67
-        return implode(', ', $this->methods);
68
-    }
62
+	/**
63
+	 * {@inheritdoc}
64
+	 */
65
+	public function getFieldValue(): string
66
+	{
67
+		return implode(', ', $this->methods);
68
+	}
69 69
 }
Please login to merge, or discard this patch.
src/Header/WWWAuthenticateHeader.php 1 patch
Indentation   +107 added lines, -107 removed lines patch added patch discarded remove patch
@@ -30,111 +30,111 @@
 block discarded – undo
30 30
 class WWWAuthenticateHeader extends Header
31 31
 {
32 32
 
33
-    /**
34
-     * @deprecated Use the {@see AuthenticationScheme} enum.
35
-     */
36
-    public const HTTP_AUTHENTICATE_SCHEME_BASIC = AuthenticationScheme::BASIC;
37
-
38
-    /**
39
-     * @deprecated Use the {@see AuthenticationScheme} enum.
40
-     */
41
-    public const HTTP_AUTHENTICATE_SCHEME_BEARER = AuthenticationScheme::BEARER;
42
-
43
-    /**
44
-     * @deprecated Use the {@see AuthenticationScheme} enum.
45
-     */
46
-    public const HTTP_AUTHENTICATE_SCHEME_DIGEST = AuthenticationScheme::DIGEST;
47
-
48
-    /**
49
-     * @deprecated Use the {@see AuthenticationScheme} enum.
50
-     */
51
-    public const HTTP_AUTHENTICATE_SCHEME_HOBA = AuthenticationScheme::HOBA;
52
-
53
-    /**
54
-     * @deprecated Use the {@see AuthenticationScheme} enum.
55
-     */
56
-    public const HTTP_AUTHENTICATE_SCHEME_MUTUAL = AuthenticationScheme::MUTUAL;
57
-
58
-    /**
59
-     * @deprecated Use the {@see AuthenticationScheme} enum.
60
-     */
61
-    public const HTTP_AUTHENTICATE_SCHEME_NEGOTIATE = AuthenticationScheme::NEGOTIATE;
62
-
63
-    /**
64
-     * @deprecated Use the {@see AuthenticationScheme} enum.
65
-     */
66
-    public const HTTP_AUTHENTICATE_SCHEME_OAUTH = AuthenticationScheme::OAUTH;
67
-
68
-    /**
69
-     * @deprecated Use the {@see AuthenticationScheme} enum.
70
-     */
71
-    public const HTTP_AUTHENTICATE_SCHEME_SCRAM_SHA_1 = AuthenticationScheme::SCRAM_SHA_1;
72
-
73
-    /**
74
-     * @deprecated Use the {@see AuthenticationScheme} enum.
75
-     */
76
-    public const HTTP_AUTHENTICATE_SCHEME_SCRAM_SHA_256 = AuthenticationScheme::SCRAM_SHA_256;
77
-
78
-    /**
79
-     * @deprecated Use the {@see AuthenticationScheme} enum.
80
-     */
81
-    public const HTTP_AUTHENTICATE_SCHEME_VAPID = AuthenticationScheme::VAPID;
82
-
83
-    /**
84
-     * @var string
85
-     */
86
-    private string $scheme;
87
-
88
-    /**
89
-     * @var array<string, string>
90
-     */
91
-    private array $parameters;
92
-
93
-    /**
94
-     * Constructor of the class
95
-     *
96
-     * @param string $scheme
97
-     * @param array<array-key, mixed> $parameters
98
-     *
99
-     * @throws InvalidHeaderException
100
-     *         - If the scheme isn't valid;
101
-     *         - If the parameters aren't valid.
102
-     */
103
-    public function __construct(string $scheme, array $parameters = [])
104
-    {
105
-        $this->validateToken($scheme);
106
-
107
-        // validate and normalize the parameters...
108
-        $parameters = $this->validateParameters($parameters);
109
-
110
-        $this->scheme = $scheme;
111
-        $this->parameters = $parameters;
112
-    }
113
-
114
-    /**
115
-     * {@inheritdoc}
116
-     */
117
-    public function getFieldName(): string
118
-    {
119
-        return 'WWW-Authenticate';
120
-    }
121
-
122
-    /**
123
-     * {@inheritdoc}
124
-     */
125
-    public function getFieldValue(): string
126
-    {
127
-        $v = $this->scheme;
128
-
129
-        $challenge = [];
130
-        foreach ($this->parameters as $name => $value) {
131
-            $challenge[] = sprintf(' %s="%s"', $name, $value);
132
-        }
133
-
134
-        if (!empty($challenge)) {
135
-            $v .= implode(',', $challenge);
136
-        }
137
-
138
-        return $v;
139
-    }
33
+	/**
34
+	 * @deprecated Use the {@see AuthenticationScheme} enum.
35
+	 */
36
+	public const HTTP_AUTHENTICATE_SCHEME_BASIC = AuthenticationScheme::BASIC;
37
+
38
+	/**
39
+	 * @deprecated Use the {@see AuthenticationScheme} enum.
40
+	 */
41
+	public const HTTP_AUTHENTICATE_SCHEME_BEARER = AuthenticationScheme::BEARER;
42
+
43
+	/**
44
+	 * @deprecated Use the {@see AuthenticationScheme} enum.
45
+	 */
46
+	public const HTTP_AUTHENTICATE_SCHEME_DIGEST = AuthenticationScheme::DIGEST;
47
+
48
+	/**
49
+	 * @deprecated Use the {@see AuthenticationScheme} enum.
50
+	 */
51
+	public const HTTP_AUTHENTICATE_SCHEME_HOBA = AuthenticationScheme::HOBA;
52
+
53
+	/**
54
+	 * @deprecated Use the {@see AuthenticationScheme} enum.
55
+	 */
56
+	public const HTTP_AUTHENTICATE_SCHEME_MUTUAL = AuthenticationScheme::MUTUAL;
57
+
58
+	/**
59
+	 * @deprecated Use the {@see AuthenticationScheme} enum.
60
+	 */
61
+	public const HTTP_AUTHENTICATE_SCHEME_NEGOTIATE = AuthenticationScheme::NEGOTIATE;
62
+
63
+	/**
64
+	 * @deprecated Use the {@see AuthenticationScheme} enum.
65
+	 */
66
+	public const HTTP_AUTHENTICATE_SCHEME_OAUTH = AuthenticationScheme::OAUTH;
67
+
68
+	/**
69
+	 * @deprecated Use the {@see AuthenticationScheme} enum.
70
+	 */
71
+	public const HTTP_AUTHENTICATE_SCHEME_SCRAM_SHA_1 = AuthenticationScheme::SCRAM_SHA_1;
72
+
73
+	/**
74
+	 * @deprecated Use the {@see AuthenticationScheme} enum.
75
+	 */
76
+	public const HTTP_AUTHENTICATE_SCHEME_SCRAM_SHA_256 = AuthenticationScheme::SCRAM_SHA_256;
77
+
78
+	/**
79
+	 * @deprecated Use the {@see AuthenticationScheme} enum.
80
+	 */
81
+	public const HTTP_AUTHENTICATE_SCHEME_VAPID = AuthenticationScheme::VAPID;
82
+
83
+	/**
84
+	 * @var string
85
+	 */
86
+	private string $scheme;
87
+
88
+	/**
89
+	 * @var array<string, string>
90
+	 */
91
+	private array $parameters;
92
+
93
+	/**
94
+	 * Constructor of the class
95
+	 *
96
+	 * @param string $scheme
97
+	 * @param array<array-key, mixed> $parameters
98
+	 *
99
+	 * @throws InvalidHeaderException
100
+	 *         - If the scheme isn't valid;
101
+	 *         - If the parameters aren't valid.
102
+	 */
103
+	public function __construct(string $scheme, array $parameters = [])
104
+	{
105
+		$this->validateToken($scheme);
106
+
107
+		// validate and normalize the parameters...
108
+		$parameters = $this->validateParameters($parameters);
109
+
110
+		$this->scheme = $scheme;
111
+		$this->parameters = $parameters;
112
+	}
113
+
114
+	/**
115
+	 * {@inheritdoc}
116
+	 */
117
+	public function getFieldName(): string
118
+	{
119
+		return 'WWW-Authenticate';
120
+	}
121
+
122
+	/**
123
+	 * {@inheritdoc}
124
+	 */
125
+	public function getFieldValue(): string
126
+	{
127
+		$v = $this->scheme;
128
+
129
+		$challenge = [];
130
+		foreach ($this->parameters as $name => $value) {
131
+			$challenge[] = sprintf(' %s="%s"', $name, $value);
132
+		}
133
+
134
+		if (!empty($challenge)) {
135
+			$v .= implode(',', $challenge);
136
+		}
137
+
138
+		return $v;
139
+	}
140 140
 }
Please login to merge, or discard this patch.
src/Header/ContentLocationHeader.php 1 patch
Indentation   +33 added lines, -33 removed lines patch added patch discarded remove patch
@@ -25,37 +25,37 @@
 block discarded – undo
25 25
 class ContentLocationHeader extends Header
26 26
 {
27 27
 
28
-    /**
29
-     * @var UriInterface
30
-     */
31
-    private UriInterface $uri;
32
-
33
-    /**
34
-     * Constructor of the class
35
-     *
36
-     * @param mixed $uri
37
-     *
38
-     * @throws InvalidUriException
39
-     *         If the URI isn't valid.
40
-     */
41
-    public function __construct($uri)
42
-    {
43
-        $this->uri = Uri::create($uri);
44
-    }
45
-
46
-    /**
47
-     * {@inheritdoc}
48
-     */
49
-    public function getFieldName(): string
50
-    {
51
-        return 'Content-Location';
52
-    }
53
-
54
-    /**
55
-     * {@inheritdoc}
56
-     */
57
-    public function getFieldValue(): string
58
-    {
59
-        return $this->uri->__toString();
60
-    }
28
+	/**
29
+	 * @var UriInterface
30
+	 */
31
+	private UriInterface $uri;
32
+
33
+	/**
34
+	 * Constructor of the class
35
+	 *
36
+	 * @param mixed $uri
37
+	 *
38
+	 * @throws InvalidUriException
39
+	 *         If the URI isn't valid.
40
+	 */
41
+	public function __construct($uri)
42
+	{
43
+		$this->uri = Uri::create($uri);
44
+	}
45
+
46
+	/**
47
+	 * {@inheritdoc}
48
+	 */
49
+	public function getFieldName(): string
50
+	{
51
+		return 'Content-Location';
52
+	}
53
+
54
+	/**
55
+	 * {@inheritdoc}
56
+	 */
57
+	public function getFieldValue(): string
58
+	{
59
+		return $this->uri->__toString();
60
+	}
61 61
 }
Please login to merge, or discard this patch.
src/Header/KeepAliveHeader.php 1 patch
Indentation   +42 added lines, -42 removed lines patch added patch discarded remove patch
@@ -29,53 +29,53 @@
 block discarded – undo
29 29
 class KeepAliveHeader extends Header
30 30
 {
31 31
 
32
-    /**
33
-     * @var array<string, string>
34
-     */
35
-    private array $parameters;
32
+	/**
33
+	 * @var array<string, string>
34
+	 */
35
+	private array $parameters;
36 36
 
37
-    /**
38
-     * Constructor of the class
39
-     *
40
-     * @param array<array-key, mixed> $parameters
41
-     *
42
-     * @throws InvalidHeaderException
43
-     *         If the parameters aren't valid.
44
-     */
45
-    public function __construct(array $parameters = [])
46
-    {
47
-        // validate and normalize the parameters...
48
-        $parameters = $this->validateParameters($parameters);
37
+	/**
38
+	 * Constructor of the class
39
+	 *
40
+	 * @param array<array-key, mixed> $parameters
41
+	 *
42
+	 * @throws InvalidHeaderException
43
+	 *         If the parameters aren't valid.
44
+	 */
45
+	public function __construct(array $parameters = [])
46
+	{
47
+		// validate and normalize the parameters...
48
+		$parameters = $this->validateParameters($parameters);
49 49
 
50
-        $this->parameters = $parameters;
51
-    }
50
+		$this->parameters = $parameters;
51
+	}
52 52
 
53
-    /**
54
-     * {@inheritdoc}
55
-     */
56
-    public function getFieldName(): string
57
-    {
58
-        return 'Keep-Alive';
59
-    }
53
+	/**
54
+	 * {@inheritdoc}
55
+	 */
56
+	public function getFieldName(): string
57
+	{
58
+		return 'Keep-Alive';
59
+	}
60 60
 
61
-    /**
62
-     * {@inheritdoc}
63
-     */
64
-    public function getFieldValue(): string
65
-    {
66
-        $segments = [];
67
-        foreach ($this->parameters as $name => $value) {
68
-            // the construction <foo=> isn't valid...
69
-            if ($value === '') {
70
-                $segments[] = $name;
71
-                continue;
72
-            }
61
+	/**
62
+	 * {@inheritdoc}
63
+	 */
64
+	public function getFieldValue(): string
65
+	{
66
+		$segments = [];
67
+		foreach ($this->parameters as $name => $value) {
68
+			// the construction <foo=> isn't valid...
69
+			if ($value === '') {
70
+				$segments[] = $name;
71
+				continue;
72
+			}
73 73
 
74
-            $format = $this->isToken($value) ? '%s=%s' : '%s="%s"';
74
+			$format = $this->isToken($value) ? '%s=%s' : '%s="%s"';
75 75
 
76
-            $segments[] = sprintf($format, $name, $value);
77
-        }
76
+			$segments[] = sprintf($format, $name, $value);
77
+		}
78 78
 
79
-        return implode(', ', $segments);
80
-    }
79
+		return implode(', ', $segments);
80
+	}
81 81
 }
Please login to merge, or discard this patch.
src/Header/ClearSiteDataHeader.php 1 patch
Indentation   +37 added lines, -37 removed lines patch added patch discarded remove patch
@@ -29,46 +29,46 @@
 block discarded – undo
29 29
 class ClearSiteDataHeader extends Header
30 30
 {
31 31
 
32
-    /**
33
-     * @var list<string>
34
-     */
35
-    private array $directives = [];
32
+	/**
33
+	 * @var list<string>
34
+	 */
35
+	private array $directives = [];
36 36
 
37
-    /**
38
-     * Constructor of the class
39
-     *
40
-     * @param string ...$directives
41
-     *
42
-     * @throws InvalidHeaderException
43
-     *         If one of the directives isn't valid.
44
-     */
45
-    public function __construct(string ...$directives)
46
-    {
47
-        $this->validateQuotedString(...$directives);
37
+	/**
38
+	 * Constructor of the class
39
+	 *
40
+	 * @param string ...$directives
41
+	 *
42
+	 * @throws InvalidHeaderException
43
+	 *         If one of the directives isn't valid.
44
+	 */
45
+	public function __construct(string ...$directives)
46
+	{
47
+		$this->validateQuotedString(...$directives);
48 48
 
49
-        foreach ($directives as $directive) {
50
-            $this->directives[] = $directive;
51
-        }
52
-    }
49
+		foreach ($directives as $directive) {
50
+			$this->directives[] = $directive;
51
+		}
52
+	}
53 53
 
54
-    /**
55
-     * {@inheritdoc}
56
-     */
57
-    public function getFieldName(): string
58
-    {
59
-        return 'Clear-Site-Data';
60
-    }
54
+	/**
55
+	 * {@inheritdoc}
56
+	 */
57
+	public function getFieldName(): string
58
+	{
59
+		return 'Clear-Site-Data';
60
+	}
61 61
 
62
-    /**
63
-     * {@inheritdoc}
64
-     */
65
-    public function getFieldValue(): string
66
-    {
67
-        $segments = [];
68
-        foreach ($this->directives as $directive) {
69
-            $segments[] = sprintf('"%s"', $directive);
70
-        }
62
+	/**
63
+	 * {@inheritdoc}
64
+	 */
65
+	public function getFieldValue(): string
66
+	{
67
+		$segments = [];
68
+		foreach ($this->directives as $directive) {
69
+			$segments[] = sprintf('"%s"', $directive);
70
+		}
71 71
 
72
-        return implode(', ', $segments);
73
-    }
72
+		return implode(', ', $segments);
73
+	}
74 74
 }
Please login to merge, or discard this patch.
src/Header/AccessControlAllowOriginHeader.php 1 patch
Indentation   +66 added lines, -66 removed lines patch added patch discarded remove patch
@@ -31,77 +31,77 @@
 block discarded – undo
31 31
 class AccessControlAllowOriginHeader extends Header
32 32
 {
33 33
 
34
-    /**
35
-     * @var UriInterface|null
36
-     */
37
-    private ?UriInterface $uri = null;
34
+	/**
35
+	 * @var UriInterface|null
36
+	 */
37
+	private ?UriInterface $uri = null;
38 38
 
39
-    /**
40
-     * Constructor of the class
41
-     *
42
-     * @param mixed $uri
43
-     *
44
-     * @throws InvalidUriException
45
-     *         If the URI isn't valid.
46
-     *
47
-     * @throws InvalidHeaderException
48
-     *         If the URI isn't valid.
49
-     */
50
-    public function __construct($uri = null)
51
-    {
52
-        if (isset($uri)) {
53
-            $uri = Uri::create($uri);
54
-            $this->validateUri($uri);
55
-            $this->uri = $uri;
56
-        }
57
-    }
39
+	/**
40
+	 * Constructor of the class
41
+	 *
42
+	 * @param mixed $uri
43
+	 *
44
+	 * @throws InvalidUriException
45
+	 *         If the URI isn't valid.
46
+	 *
47
+	 * @throws InvalidHeaderException
48
+	 *         If the URI isn't valid.
49
+	 */
50
+	public function __construct($uri = null)
51
+	{
52
+		if (isset($uri)) {
53
+			$uri = Uri::create($uri);
54
+			$this->validateUri($uri);
55
+			$this->uri = $uri;
56
+		}
57
+	}
58 58
 
59
-    /**
60
-     * {@inheritdoc}
61
-     */
62
-    public function getFieldName(): string
63
-    {
64
-        return 'Access-Control-Allow-Origin';
65
-    }
59
+	/**
60
+	 * {@inheritdoc}
61
+	 */
62
+	public function getFieldName(): string
63
+	{
64
+		return 'Access-Control-Allow-Origin';
65
+	}
66 66
 
67
-    /**
68
-     * {@inheritdoc}
69
-     */
70
-    public function getFieldValue(): string
71
-    {
72
-        if (!isset($this->uri)) {
73
-            return '*';
74
-        }
67
+	/**
68
+	 * {@inheritdoc}
69
+	 */
70
+	public function getFieldValue(): string
71
+	{
72
+		if (!isset($this->uri)) {
73
+			return '*';
74
+		}
75 75
 
76
-        $origin = $this->uri->getScheme() . ':';
77
-        $origin .= '//' . $this->uri->getHost();
76
+		$origin = $this->uri->getScheme() . ':';
77
+		$origin .= '//' . $this->uri->getHost();
78 78
 
79
-        $port = $this->uri->getPort();
80
-        if (isset($port)) {
81
-            $origin .= ':' . $port;
82
-        }
79
+		$port = $this->uri->getPort();
80
+		if (isset($port)) {
81
+			$origin .= ':' . $port;
82
+		}
83 83
 
84
-        return $origin;
85
-    }
84
+		return $origin;
85
+	}
86 86
 
87
-    /**
88
-     * Validates the given URI
89
-     *
90
-     * @param UriInterface $uri
91
-     *
92
-     * @return void
93
-     *
94
-     * @throws InvalidHeaderException
95
-     *         If the URI isn't valid.
96
-     */
97
-    private function validateUri(UriInterface $uri): void
98
-    {
99
-        if ($uri->getScheme() === '' || $uri->getHost() === '') {
100
-            throw new InvalidHeaderException(sprintf(
101
-                'The URI "%2$s" for the header "%1$s" is not valid',
102
-                $this->getFieldName(),
103
-                $uri->__toString()
104
-            ));
105
-        }
106
-    }
87
+	/**
88
+	 * Validates the given URI
89
+	 *
90
+	 * @param UriInterface $uri
91
+	 *
92
+	 * @return void
93
+	 *
94
+	 * @throws InvalidHeaderException
95
+	 *         If the URI isn't valid.
96
+	 */
97
+	private function validateUri(UriInterface $uri): void
98
+	{
99
+		if ($uri->getScheme() === '' || $uri->getHost() === '') {
100
+			throw new InvalidHeaderException(sprintf(
101
+				'The URI "%2$s" for the header "%1$s" is not valid',
102
+				$this->getFieldName(),
103
+				$uri->__toString()
104
+			));
105
+		}
106
+	}
107 107
 }
Please login to merge, or discard this patch.
src/Uri.php 1 patch
Indentation   +474 added lines, -474 removed lines patch added patch discarded remove patch
@@ -43,478 +43,478 @@
 block discarded – undo
43 43
 class Uri implements UriInterface
44 44
 {
45 45
 
46
-    /**
47
-     * Scheme of the URI
48
-     *
49
-     * @var string
50
-     */
51
-    private string $scheme = '';
52
-
53
-    /**
54
-     * User Information of the URI
55
-     *
56
-     * @var string
57
-     */
58
-    private string $userInfo = '';
59
-
60
-    /**
61
-     * Host of the URI
62
-     *
63
-     * @var string
64
-     */
65
-    private string $host = '';
66
-
67
-    /**
68
-     * Port of the URI
69
-     *
70
-     * @var int|null
71
-     */
72
-    private ?int $port = null;
73
-
74
-    /**
75
-     * Path of the URI
76
-     *
77
-     * @var string
78
-     */
79
-    private string $path = '';
80
-
81
-    /**
82
-     * Query of the URI
83
-     *
84
-     * @var string
85
-     */
86
-    private string $query = '';
87
-
88
-    /**
89
-     * Fragment of the URI
90
-     *
91
-     * @var string
92
-     */
93
-    private string $fragment = '';
94
-
95
-    /**
96
-     * Constructor of the class
97
-     *
98
-     * @param string $uri
99
-     *
100
-     * @throws InvalidUriException
101
-     *         If the URI isn't valid.
102
-     */
103
-    public function __construct(string $uri = '')
104
-    {
105
-        if ($uri === '') {
106
-            return;
107
-        }
108
-
109
-        $components = parse_url($uri);
110
-        if ($components === false) {
111
-            throw new InvalidUriException('Unable to parse URI');
112
-        }
113
-
114
-        if (isset($components['scheme'])) {
115
-            $this->setScheme($components['scheme']);
116
-        }
117
-
118
-        if (isset($components['user'])) {
119
-            $this->setUserInfo(
120
-                $components['user'],
121
-                $components['pass'] ?? null
122
-            );
123
-        }
124
-
125
-        if (isset($components['host'])) {
126
-            $this->setHost($components['host']);
127
-        }
128
-
129
-        if (isset($components['port'])) {
130
-            $this->setPort($components['port']);
131
-        }
132
-
133
-        if (isset($components['path'])) {
134
-            $this->setPath($components['path']);
135
-        }
136
-
137
-        if (isset($components['query'])) {
138
-            $this->setQuery($components['query']);
139
-        }
140
-
141
-        if (isset($components['fragment'])) {
142
-            $this->setFragment($components['fragment']);
143
-        }
144
-    }
145
-
146
-    /**
147
-     * Creates a URI
148
-     *
149
-     * @param mixed $uri
150
-     *
151
-     * @return UriInterface
152
-     *
153
-     * @throws InvalidArgumentException
154
-     *         If the URI isn't valid.
155
-     */
156
-    public static function create($uri): UriInterface
157
-    {
158
-        if ($uri instanceof UriInterface) {
159
-            return $uri;
160
-        }
161
-
162
-        if (!is_string($uri)) {
163
-            throw new InvalidArgumentException('URI should be a string');
164
-        }
165
-
166
-        return new self($uri);
167
-    }
168
-
169
-    /**
170
-     * {@inheritdoc}
171
-     *
172
-     * @throws InvalidUriComponentException
173
-     *         If the scheme isn't valid.
174
-     */
175
-    public function withScheme($scheme): UriInterface
176
-    {
177
-        $clone = clone $this;
178
-        $clone->setScheme($scheme);
179
-
180
-        return $clone;
181
-    }
182
-
183
-    /**
184
-     * {@inheritdoc}
185
-     *
186
-     * @throws InvalidUriComponentException
187
-     *         If the user information isn't valid.
188
-     */
189
-    public function withUserInfo($user, $password = null): UriInterface
190
-    {
191
-        $clone = clone $this;
192
-        $clone->setUserInfo($user, $password);
193
-
194
-        return $clone;
195
-    }
196
-
197
-    /**
198
-     * {@inheritdoc}
199
-     *
200
-     * @throws InvalidUriComponentException
201
-     *         If the host isn't valid.
202
-     */
203
-    public function withHost($host): UriInterface
204
-    {
205
-        $clone = clone $this;
206
-        $clone->setHost($host);
207
-
208
-        return $clone;
209
-    }
210
-
211
-    /**
212
-     * {@inheritdoc}
213
-     *
214
-     * @throws InvalidUriComponentException
215
-     *         If the port isn't valid.
216
-     */
217
-    public function withPort($port): UriInterface
218
-    {
219
-        $clone = clone $this;
220
-        $clone->setPort($port);
221
-
222
-        return $clone;
223
-    }
224
-
225
-    /**
226
-     * {@inheritdoc}
227
-     *
228
-     * @throws InvalidUriComponentException
229
-     *         If the path isn't valid.
230
-     */
231
-    public function withPath($path): UriInterface
232
-    {
233
-        $clone = clone $this;
234
-        $clone->setPath($path);
235
-
236
-        return $clone;
237
-    }
238
-
239
-    /**
240
-     * {@inheritdoc}
241
-     *
242
-     * @throws InvalidUriComponentException
243
-     *         If the query isn't valid.
244
-     */
245
-    public function withQuery($query): UriInterface
246
-    {
247
-        $clone = clone $this;
248
-        $clone->setQuery($query);
249
-
250
-        return $clone;
251
-    }
252
-
253
-    /**
254
-     * {@inheritdoc}
255
-     *
256
-     * @throws InvalidUriComponentException
257
-     *         If the fragment isn't valid.
258
-     */
259
-    public function withFragment($fragment): UriInterface
260
-    {
261
-        $clone = clone $this;
262
-        $clone->setFragment($fragment);
263
-
264
-        return $clone;
265
-    }
266
-
267
-    /**
268
-     * {@inheritdoc}
269
-     */
270
-    public function getScheme(): string
271
-    {
272
-        return $this->scheme;
273
-    }
274
-
275
-    /**
276
-     * {@inheritdoc}
277
-     */
278
-    public function getUserInfo(): string
279
-    {
280
-        return $this->userInfo;
281
-    }
282
-
283
-    /**
284
-     * {@inheritdoc}
285
-     */
286
-    public function getHost(): string
287
-    {
288
-        return $this->host;
289
-    }
290
-
291
-    /**
292
-     * {@inheritdoc}
293
-     */
294
-    public function getPort(): ?int
295
-    {
296
-        // The 80 is the default port number for the HTTP protocol.
297
-        if ($this->port === 80 && $this->scheme === 'http') {
298
-            return null;
299
-        }
300
-
301
-        // The 443 is the default port number for the HTTPS protocol.
302
-        if ($this->port === 443 && $this->scheme === 'https') {
303
-            return null;
304
-        }
305
-
306
-        return $this->port;
307
-    }
308
-
309
-    /**
310
-     * {@inheritdoc}
311
-     */
312
-    public function getPath(): string
313
-    {
314
-        // CVE-2015-3257
315
-        if (strncmp($this->path, '//', 2) === 0) {
316
-            return '/' . ltrim($this->path, '/');
317
-        }
318
-
319
-        return $this->path;
320
-    }
321
-
322
-    /**
323
-     * {@inheritdoc}
324
-     */
325
-    public function getQuery(): string
326
-    {
327
-        return $this->query;
328
-    }
329
-
330
-    /**
331
-     * {@inheritdoc}
332
-     */
333
-    public function getFragment(): string
334
-    {
335
-        return $this->fragment;
336
-    }
337
-
338
-    /**
339
-     * {@inheritdoc}
340
-     */
341
-    public function getAuthority(): string
342
-    {
343
-        // The host is the basic subcomponent.
344
-        if ($this->host === '') {
345
-            return '';
346
-        }
347
-
348
-        $authority = $this->host;
349
-        if ($this->userInfo !== '') {
350
-            $authority = $this->userInfo . '@' . $authority;
351
-        }
352
-
353
-        $port = $this->getPort();
354
-        if ($port !== null) {
355
-            $authority = $authority . ':' . $port;
356
-        }
357
-
358
-        return $authority;
359
-    }
360
-
361
-    /**
362
-     * {@inheritdoc}
363
-     */
364
-    public function __toString(): string
365
-    {
366
-        $uri = '';
367
-
368
-        $scheme = $this->scheme;
369
-        if ($scheme !== '') {
370
-            $uri .= $scheme . ':';
371
-        }
372
-
373
-        $authority = $this->getAuthority();
374
-        if ($authority !== '') {
375
-            $uri .= '//' . $authority;
376
-        }
377
-
378
-        $path = $this->path;
379
-        if ($path !== '') {
380
-            // https://github.com/sunrise-php/uri/issues/31
381
-            // https://datatracker.ietf.org/doc/html/rfc3986#section-3.3
382
-            //
383
-            // If a URI contains an authority component,
384
-            // then the path component must either be empty
385
-            // or begin with a slash ("/") character.
386
-            if ($authority !== '' && strncmp($path, '/', 1) !== 0) {
387
-                $path = '/' . $path;
388
-            }
389
-
390
-            // https://github.com/sunrise-php/uri/issues/31
391
-            // https://datatracker.ietf.org/doc/html/rfc3986#section-3.3
392
-            //
393
-            // If a URI does not contain an authority component,
394
-            // then the path cannot begin with two slash characters ("//").
395
-            if ($authority === '' && strncmp($path, '//', 2) === 0) {
396
-                $path = '/' . ltrim($path, '/');
397
-            }
398
-
399
-            $uri .= $path;
400
-        }
401
-
402
-        $query = $this->query;
403
-        if ($query !== '') {
404
-            $uri .= '?' . $query;
405
-        }
406
-
407
-        $fragment = $this->fragment;
408
-        if ($fragment !== '') {
409
-            $uri .= '#' . $fragment;
410
-        }
411
-
412
-        return $uri;
413
-    }
414
-
415
-    /**
416
-     * Sets the given scheme to the URI
417
-     *
418
-     * @param mixed $scheme
419
-     *
420
-     * @return void
421
-     *
422
-     * @throws InvalidUriComponentException
423
-     *         If the scheme isn't valid.
424
-     */
425
-    final protected function setScheme($scheme): void
426
-    {
427
-        $this->scheme = (new Scheme($scheme))->getValue();
428
-    }
429
-
430
-    /**
431
-     * Sets the given user information to the URI
432
-     *
433
-     * @param mixed $user
434
-     * @param mixed $password
435
-     *
436
-     * @return void
437
-     *
438
-     * @throws InvalidUriComponentException
439
-     *         If the user information isn't valid.
440
-     */
441
-    final protected function setUserInfo($user, $password): void
442
-    {
443
-        $this->userInfo = (new UserInfo($user, $password))->getValue();
444
-    }
445
-
446
-    /**
447
-     * Sets the given host to the URI
448
-     *
449
-     * @param mixed $host
450
-     *
451
-     * @return void
452
-     *
453
-     * @throws InvalidUriComponentException
454
-     *         If the host isn't valid.
455
-     */
456
-    final protected function setHost($host): void
457
-    {
458
-        $this->host = (new Host($host))->getValue();
459
-    }
460
-
461
-    /**
462
-     * Sets the given port to the URI
463
-     *
464
-     * @param mixed $port
465
-     *
466
-     * @return void
467
-     *
468
-     * @throws InvalidUriComponentException
469
-     *         If the port isn't valid.
470
-     */
471
-    final protected function setPort($port): void
472
-    {
473
-        $this->port = (new Port($port))->getValue();
474
-    }
475
-
476
-    /**
477
-     * Sets the given path to the URI
478
-     *
479
-     * @param mixed $path
480
-     *
481
-     * @return void
482
-     *
483
-     * @throws InvalidUriComponentException
484
-     *         If the path isn't valid.
485
-     */
486
-    final protected function setPath($path): void
487
-    {
488
-        $this->path = (new Path($path))->getValue();
489
-    }
490
-
491
-    /**
492
-     * Sets the given query to the URI
493
-     *
494
-     * @param mixed $query
495
-     *
496
-     * @return void
497
-     *
498
-     * @throws InvalidUriComponentException
499
-     *         If the query isn't valid.
500
-     */
501
-    final protected function setQuery($query): void
502
-    {
503
-        $this->query = (new Query($query))->getValue();
504
-    }
505
-
506
-    /**
507
-     * Sets the given fragment to the URI
508
-     *
509
-     * @param mixed $fragment
510
-     *
511
-     * @return void
512
-     *
513
-     * @throws InvalidUriComponentException
514
-     *         If the fragment isn't valid.
515
-     */
516
-    final protected function setFragment($fragment): void
517
-    {
518
-        $this->fragment = (new Fragment($fragment))->getValue();
519
-    }
46
+	/**
47
+	 * Scheme of the URI
48
+	 *
49
+	 * @var string
50
+	 */
51
+	private string $scheme = '';
52
+
53
+	/**
54
+	 * User Information of the URI
55
+	 *
56
+	 * @var string
57
+	 */
58
+	private string $userInfo = '';
59
+
60
+	/**
61
+	 * Host of the URI
62
+	 *
63
+	 * @var string
64
+	 */
65
+	private string $host = '';
66
+
67
+	/**
68
+	 * Port of the URI
69
+	 *
70
+	 * @var int|null
71
+	 */
72
+	private ?int $port = null;
73
+
74
+	/**
75
+	 * Path of the URI
76
+	 *
77
+	 * @var string
78
+	 */
79
+	private string $path = '';
80
+
81
+	/**
82
+	 * Query of the URI
83
+	 *
84
+	 * @var string
85
+	 */
86
+	private string $query = '';
87
+
88
+	/**
89
+	 * Fragment of the URI
90
+	 *
91
+	 * @var string
92
+	 */
93
+	private string $fragment = '';
94
+
95
+	/**
96
+	 * Constructor of the class
97
+	 *
98
+	 * @param string $uri
99
+	 *
100
+	 * @throws InvalidUriException
101
+	 *         If the URI isn't valid.
102
+	 */
103
+	public function __construct(string $uri = '')
104
+	{
105
+		if ($uri === '') {
106
+			return;
107
+		}
108
+
109
+		$components = parse_url($uri);
110
+		if ($components === false) {
111
+			throw new InvalidUriException('Unable to parse URI');
112
+		}
113
+
114
+		if (isset($components['scheme'])) {
115
+			$this->setScheme($components['scheme']);
116
+		}
117
+
118
+		if (isset($components['user'])) {
119
+			$this->setUserInfo(
120
+				$components['user'],
121
+				$components['pass'] ?? null
122
+			);
123
+		}
124
+
125
+		if (isset($components['host'])) {
126
+			$this->setHost($components['host']);
127
+		}
128
+
129
+		if (isset($components['port'])) {
130
+			$this->setPort($components['port']);
131
+		}
132
+
133
+		if (isset($components['path'])) {
134
+			$this->setPath($components['path']);
135
+		}
136
+
137
+		if (isset($components['query'])) {
138
+			$this->setQuery($components['query']);
139
+		}
140
+
141
+		if (isset($components['fragment'])) {
142
+			$this->setFragment($components['fragment']);
143
+		}
144
+	}
145
+
146
+	/**
147
+	 * Creates a URI
148
+	 *
149
+	 * @param mixed $uri
150
+	 *
151
+	 * @return UriInterface
152
+	 *
153
+	 * @throws InvalidArgumentException
154
+	 *         If the URI isn't valid.
155
+	 */
156
+	public static function create($uri): UriInterface
157
+	{
158
+		if ($uri instanceof UriInterface) {
159
+			return $uri;
160
+		}
161
+
162
+		if (!is_string($uri)) {
163
+			throw new InvalidArgumentException('URI should be a string');
164
+		}
165
+
166
+		return new self($uri);
167
+	}
168
+
169
+	/**
170
+	 * {@inheritdoc}
171
+	 *
172
+	 * @throws InvalidUriComponentException
173
+	 *         If the scheme isn't valid.
174
+	 */
175
+	public function withScheme($scheme): UriInterface
176
+	{
177
+		$clone = clone $this;
178
+		$clone->setScheme($scheme);
179
+
180
+		return $clone;
181
+	}
182
+
183
+	/**
184
+	 * {@inheritdoc}
185
+	 *
186
+	 * @throws InvalidUriComponentException
187
+	 *         If the user information isn't valid.
188
+	 */
189
+	public function withUserInfo($user, $password = null): UriInterface
190
+	{
191
+		$clone = clone $this;
192
+		$clone->setUserInfo($user, $password);
193
+
194
+		return $clone;
195
+	}
196
+
197
+	/**
198
+	 * {@inheritdoc}
199
+	 *
200
+	 * @throws InvalidUriComponentException
201
+	 *         If the host isn't valid.
202
+	 */
203
+	public function withHost($host): UriInterface
204
+	{
205
+		$clone = clone $this;
206
+		$clone->setHost($host);
207
+
208
+		return $clone;
209
+	}
210
+
211
+	/**
212
+	 * {@inheritdoc}
213
+	 *
214
+	 * @throws InvalidUriComponentException
215
+	 *         If the port isn't valid.
216
+	 */
217
+	public function withPort($port): UriInterface
218
+	{
219
+		$clone = clone $this;
220
+		$clone->setPort($port);
221
+
222
+		return $clone;
223
+	}
224
+
225
+	/**
226
+	 * {@inheritdoc}
227
+	 *
228
+	 * @throws InvalidUriComponentException
229
+	 *         If the path isn't valid.
230
+	 */
231
+	public function withPath($path): UriInterface
232
+	{
233
+		$clone = clone $this;
234
+		$clone->setPath($path);
235
+
236
+		return $clone;
237
+	}
238
+
239
+	/**
240
+	 * {@inheritdoc}
241
+	 *
242
+	 * @throws InvalidUriComponentException
243
+	 *         If the query isn't valid.
244
+	 */
245
+	public function withQuery($query): UriInterface
246
+	{
247
+		$clone = clone $this;
248
+		$clone->setQuery($query);
249
+
250
+		return $clone;
251
+	}
252
+
253
+	/**
254
+	 * {@inheritdoc}
255
+	 *
256
+	 * @throws InvalidUriComponentException
257
+	 *         If the fragment isn't valid.
258
+	 */
259
+	public function withFragment($fragment): UriInterface
260
+	{
261
+		$clone = clone $this;
262
+		$clone->setFragment($fragment);
263
+
264
+		return $clone;
265
+	}
266
+
267
+	/**
268
+	 * {@inheritdoc}
269
+	 */
270
+	public function getScheme(): string
271
+	{
272
+		return $this->scheme;
273
+	}
274
+
275
+	/**
276
+	 * {@inheritdoc}
277
+	 */
278
+	public function getUserInfo(): string
279
+	{
280
+		return $this->userInfo;
281
+	}
282
+
283
+	/**
284
+	 * {@inheritdoc}
285
+	 */
286
+	public function getHost(): string
287
+	{
288
+		return $this->host;
289
+	}
290
+
291
+	/**
292
+	 * {@inheritdoc}
293
+	 */
294
+	public function getPort(): ?int
295
+	{
296
+		// The 80 is the default port number for the HTTP protocol.
297
+		if ($this->port === 80 && $this->scheme === 'http') {
298
+			return null;
299
+		}
300
+
301
+		// The 443 is the default port number for the HTTPS protocol.
302
+		if ($this->port === 443 && $this->scheme === 'https') {
303
+			return null;
304
+		}
305
+
306
+		return $this->port;
307
+	}
308
+
309
+	/**
310
+	 * {@inheritdoc}
311
+	 */
312
+	public function getPath(): string
313
+	{
314
+		// CVE-2015-3257
315
+		if (strncmp($this->path, '//', 2) === 0) {
316
+			return '/' . ltrim($this->path, '/');
317
+		}
318
+
319
+		return $this->path;
320
+	}
321
+
322
+	/**
323
+	 * {@inheritdoc}
324
+	 */
325
+	public function getQuery(): string
326
+	{
327
+		return $this->query;
328
+	}
329
+
330
+	/**
331
+	 * {@inheritdoc}
332
+	 */
333
+	public function getFragment(): string
334
+	{
335
+		return $this->fragment;
336
+	}
337
+
338
+	/**
339
+	 * {@inheritdoc}
340
+	 */
341
+	public function getAuthority(): string
342
+	{
343
+		// The host is the basic subcomponent.
344
+		if ($this->host === '') {
345
+			return '';
346
+		}
347
+
348
+		$authority = $this->host;
349
+		if ($this->userInfo !== '') {
350
+			$authority = $this->userInfo . '@' . $authority;
351
+		}
352
+
353
+		$port = $this->getPort();
354
+		if ($port !== null) {
355
+			$authority = $authority . ':' . $port;
356
+		}
357
+
358
+		return $authority;
359
+	}
360
+
361
+	/**
362
+	 * {@inheritdoc}
363
+	 */
364
+	public function __toString(): string
365
+	{
366
+		$uri = '';
367
+
368
+		$scheme = $this->scheme;
369
+		if ($scheme !== '') {
370
+			$uri .= $scheme . ':';
371
+		}
372
+
373
+		$authority = $this->getAuthority();
374
+		if ($authority !== '') {
375
+			$uri .= '//' . $authority;
376
+		}
377
+
378
+		$path = $this->path;
379
+		if ($path !== '') {
380
+			// https://github.com/sunrise-php/uri/issues/31
381
+			// https://datatracker.ietf.org/doc/html/rfc3986#section-3.3
382
+			//
383
+			// If a URI contains an authority component,
384
+			// then the path component must either be empty
385
+			// or begin with a slash ("/") character.
386
+			if ($authority !== '' && strncmp($path, '/', 1) !== 0) {
387
+				$path = '/' . $path;
388
+			}
389
+
390
+			// https://github.com/sunrise-php/uri/issues/31
391
+			// https://datatracker.ietf.org/doc/html/rfc3986#section-3.3
392
+			//
393
+			// If a URI does not contain an authority component,
394
+			// then the path cannot begin with two slash characters ("//").
395
+			if ($authority === '' && strncmp($path, '//', 2) === 0) {
396
+				$path = '/' . ltrim($path, '/');
397
+			}
398
+
399
+			$uri .= $path;
400
+		}
401
+
402
+		$query = $this->query;
403
+		if ($query !== '') {
404
+			$uri .= '?' . $query;
405
+		}
406
+
407
+		$fragment = $this->fragment;
408
+		if ($fragment !== '') {
409
+			$uri .= '#' . $fragment;
410
+		}
411
+
412
+		return $uri;
413
+	}
414
+
415
+	/**
416
+	 * Sets the given scheme to the URI
417
+	 *
418
+	 * @param mixed $scheme
419
+	 *
420
+	 * @return void
421
+	 *
422
+	 * @throws InvalidUriComponentException
423
+	 *         If the scheme isn't valid.
424
+	 */
425
+	final protected function setScheme($scheme): void
426
+	{
427
+		$this->scheme = (new Scheme($scheme))->getValue();
428
+	}
429
+
430
+	/**
431
+	 * Sets the given user information to the URI
432
+	 *
433
+	 * @param mixed $user
434
+	 * @param mixed $password
435
+	 *
436
+	 * @return void
437
+	 *
438
+	 * @throws InvalidUriComponentException
439
+	 *         If the user information isn't valid.
440
+	 */
441
+	final protected function setUserInfo($user, $password): void
442
+	{
443
+		$this->userInfo = (new UserInfo($user, $password))->getValue();
444
+	}
445
+
446
+	/**
447
+	 * Sets the given host to the URI
448
+	 *
449
+	 * @param mixed $host
450
+	 *
451
+	 * @return void
452
+	 *
453
+	 * @throws InvalidUriComponentException
454
+	 *         If the host isn't valid.
455
+	 */
456
+	final protected function setHost($host): void
457
+	{
458
+		$this->host = (new Host($host))->getValue();
459
+	}
460
+
461
+	/**
462
+	 * Sets the given port to the URI
463
+	 *
464
+	 * @param mixed $port
465
+	 *
466
+	 * @return void
467
+	 *
468
+	 * @throws InvalidUriComponentException
469
+	 *         If the port isn't valid.
470
+	 */
471
+	final protected function setPort($port): void
472
+	{
473
+		$this->port = (new Port($port))->getValue();
474
+	}
475
+
476
+	/**
477
+	 * Sets the given path to the URI
478
+	 *
479
+	 * @param mixed $path
480
+	 *
481
+	 * @return void
482
+	 *
483
+	 * @throws InvalidUriComponentException
484
+	 *         If the path isn't valid.
485
+	 */
486
+	final protected function setPath($path): void
487
+	{
488
+		$this->path = (new Path($path))->getValue();
489
+	}
490
+
491
+	/**
492
+	 * Sets the given query to the URI
493
+	 *
494
+	 * @param mixed $query
495
+	 *
496
+	 * @return void
497
+	 *
498
+	 * @throws InvalidUriComponentException
499
+	 *         If the query isn't valid.
500
+	 */
501
+	final protected function setQuery($query): void
502
+	{
503
+		$this->query = (new Query($query))->getValue();
504
+	}
505
+
506
+	/**
507
+	 * Sets the given fragment to the URI
508
+	 *
509
+	 * @param mixed $fragment
510
+	 *
511
+	 * @return void
512
+	 *
513
+	 * @throws InvalidUriComponentException
514
+	 *         If the fragment isn't valid.
515
+	 */
516
+	final protected function setFragment($fragment): void
517
+	{
518
+		$this->fragment = (new Fragment($fragment))->getValue();
519
+	}
520 520
 }
Please login to merge, or discard this patch.
src/UploadedFile.php 1 patch
Indentation   +227 added lines, -227 removed lines patch added patch discarded remove patch
@@ -49,231 +49,231 @@
 block discarded – undo
49 49
 class UploadedFile implements UploadedFileInterface
50 50
 {
51 51
 
52
-    /**
53
-     * List of upload errors
54
-     *
55
-     * @link https://www.php.net/manual/en/features.file-upload.errors.php
56
-     *
57
-     * @var array<int, string>
58
-     */
59
-    public const UPLOAD_ERRORS = [
60
-        UPLOAD_ERR_OK         => 'No error',
61
-        UPLOAD_ERR_INI_SIZE   => 'Uploaded file exceeds the upload_max_filesize directive in php.ini',
62
-        UPLOAD_ERR_FORM_SIZE  => 'Uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the form',
63
-        UPLOAD_ERR_PARTIAL    => 'Uploaded file was only partially uploaded',
64
-        UPLOAD_ERR_NO_FILE    => 'No file was uploaded',
65
-        UPLOAD_ERR_NO_TMP_DIR => 'Missing a temporary folder',
66
-        UPLOAD_ERR_CANT_WRITE => 'Failed to write file to disk',
67
-        UPLOAD_ERR_EXTENSION  => 'File upload stopped by extension',
68
-    ];
69
-
70
-    /**
71
-     * The file stream
72
-     *
73
-     * @var StreamInterface|null
74
-     */
75
-    private ?StreamInterface $stream = null;
76
-
77
-    /**
78
-     * The file size
79
-     *
80
-     * @var int|null
81
-     */
82
-    private ?int $size;
83
-
84
-    /**
85
-     * The file's error code
86
-     *
87
-     * @var int
88
-     */
89
-    private int $errorCode;
90
-
91
-    /**
92
-     * The file's error message
93
-     *
94
-     * @var string
95
-     */
96
-    private string $errorMessage;
97
-
98
-    /**
99
-     * The client's file name
100
-     *
101
-     * @var string|null
102
-     */
103
-    private ?string $clientFilename;
104
-
105
-    /**
106
-     * The client's file media type
107
-     *
108
-     * @var string|null
109
-     */
110
-    private ?string $clientMediaType;
111
-
112
-    /**
113
-     * Constructor of the class
114
-     *
115
-     * @param StreamInterface $stream
116
-     * @param int|null $size
117
-     * @param int $error
118
-     * @param string|null $clientFilename
119
-     * @param string|null $clientMediaType
120
-     */
121
-    public function __construct(
122
-        StreamInterface $stream,
123
-        ?int $size = null,
124
-        int $error = UPLOAD_ERR_OK,
125
-        ?string $clientFilename = null,
126
-        ?string $clientMediaType = null
127
-    ) {
128
-        if (UPLOAD_ERR_OK === $error) {
129
-            $this->stream = $stream;
130
-        }
131
-
132
-        $message = self::UPLOAD_ERRORS[$error] ?? 'Unknown error';
133
-
134
-        $this->size = $size;
135
-        $this->errorCode = $error;
136
-        $this->errorMessage = $message;
137
-        $this->clientFilename = $clientFilename;
138
-        $this->clientMediaType = $clientMediaType;
139
-    }
140
-
141
-    /**
142
-     * Gets the file stream
143
-     *
144
-     * @return StreamInterface
145
-     *
146
-     * @throws RuntimeException
147
-     *         - If the file has no a stream due to an error;
148
-     *         - If the file was already moved.
149
-     */
150
-    public function getStream(): StreamInterface
151
-    {
152
-        if (UPLOAD_ERR_OK <> $this->errorCode) {
153
-            throw new RuntimeException(sprintf(
154
-                'Uploaded file has no a stream due to the error #%d (%s)',
155
-                $this->errorCode,
156
-                $this->errorMessage
157
-            ));
158
-        }
159
-
160
-        if (!isset($this->stream)) {
161
-            throw new RuntimeException(
162
-                'Uploaded file has no a stream because it was already moved'
163
-            );
164
-        }
165
-
166
-        return $this->stream;
167
-    }
168
-
169
-    /**
170
-     * Moves the file to the given path
171
-     *
172
-     * @param string $targetPath
173
-     *
174
-     * @return void
175
-     *
176
-     * @throws RuntimeException
177
-     *         - If the file has no a stream due to an error;
178
-     *         - If the file was already moved;
179
-     *         - If the file cannot be read;
180
-     *         - If the target path cannot be used.
181
-     */
182
-    public function moveTo($targetPath): void
183
-    {
184
-        if (UPLOAD_ERR_OK <> $this->errorCode) {
185
-            throw new RuntimeException(sprintf(
186
-                'Uploaded file cannot be moved due to the error #%d (%s)',
187
-                $this->errorCode,
188
-                $this->errorMessage
189
-            ));
190
-        }
191
-
192
-        if (!isset($this->stream)) {
193
-            throw new RuntimeException(
194
-                'Uploaded file cannot be moved because it was already moved'
195
-            );
196
-        }
197
-
198
-        if (!$this->stream->isReadable()) {
199
-            throw new RuntimeException(
200
-                'Uploaded file cannot be moved because it is not readable'
201
-            );
202
-        }
203
-
204
-        $targetDir = dirname($targetPath);
205
-        if (!is_dir($targetDir) || !is_writable($targetDir)) {
206
-            throw new RuntimeException(sprintf(
207
-                'Uploaded file cannot be moved because the directory "%s" is not writable',
208
-                $targetDir
209
-            ));
210
-        }
211
-
212
-        $targetStream = new FileStream($targetPath, 'wb');
213
-
214
-        if ($this->stream->isSeekable()) {
215
-            $this->stream->rewind();
216
-        }
217
-
218
-        while (!$this->stream->eof()) {
219
-            $targetStream->write(
220
-                $this->stream->read(4096)
221
-            );
222
-        }
223
-
224
-        $targetStream->close();
225
-
226
-        /** @var string|null */
227
-        $sourcePath = $this->stream->getMetadata('uri');
228
-
229
-        $this->stream->close();
230
-        $this->stream = null;
231
-
232
-        if (isset($sourcePath) && is_file($sourcePath)) {
233
-            $sourceDir = dirname($sourcePath);
234
-            if (is_writable($sourceDir)) {
235
-                unlink($sourcePath);
236
-            }
237
-        }
238
-    }
239
-
240
-    /**
241
-     * Gets the file size
242
-     *
243
-     * @return int|null
244
-     */
245
-    public function getSize(): ?int
246
-    {
247
-        return $this->size;
248
-    }
249
-
250
-    /**
251
-     * Gets the file's error code
252
-     *
253
-     * @return int
254
-     */
255
-    public function getError(): int
256
-    {
257
-        return $this->errorCode;
258
-    }
259
-
260
-    /**
261
-     * Gets the client's file name
262
-     *
263
-     * @return string|null
264
-     */
265
-    public function getClientFilename(): ?string
266
-    {
267
-        return $this->clientFilename;
268
-    }
269
-
270
-    /**
271
-     * Gets the client's file media type
272
-     *
273
-     * @return string|null
274
-     */
275
-    public function getClientMediaType(): ?string
276
-    {
277
-        return $this->clientMediaType;
278
-    }
52
+	/**
53
+	 * List of upload errors
54
+	 *
55
+	 * @link https://www.php.net/manual/en/features.file-upload.errors.php
56
+	 *
57
+	 * @var array<int, string>
58
+	 */
59
+	public const UPLOAD_ERRORS = [
60
+		UPLOAD_ERR_OK         => 'No error',
61
+		UPLOAD_ERR_INI_SIZE   => 'Uploaded file exceeds the upload_max_filesize directive in php.ini',
62
+		UPLOAD_ERR_FORM_SIZE  => 'Uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the form',
63
+		UPLOAD_ERR_PARTIAL    => 'Uploaded file was only partially uploaded',
64
+		UPLOAD_ERR_NO_FILE    => 'No file was uploaded',
65
+		UPLOAD_ERR_NO_TMP_DIR => 'Missing a temporary folder',
66
+		UPLOAD_ERR_CANT_WRITE => 'Failed to write file to disk',
67
+		UPLOAD_ERR_EXTENSION  => 'File upload stopped by extension',
68
+	];
69
+
70
+	/**
71
+	 * The file stream
72
+	 *
73
+	 * @var StreamInterface|null
74
+	 */
75
+	private ?StreamInterface $stream = null;
76
+
77
+	/**
78
+	 * The file size
79
+	 *
80
+	 * @var int|null
81
+	 */
82
+	private ?int $size;
83
+
84
+	/**
85
+	 * The file's error code
86
+	 *
87
+	 * @var int
88
+	 */
89
+	private int $errorCode;
90
+
91
+	/**
92
+	 * The file's error message
93
+	 *
94
+	 * @var string
95
+	 */
96
+	private string $errorMessage;
97
+
98
+	/**
99
+	 * The client's file name
100
+	 *
101
+	 * @var string|null
102
+	 */
103
+	private ?string $clientFilename;
104
+
105
+	/**
106
+	 * The client's file media type
107
+	 *
108
+	 * @var string|null
109
+	 */
110
+	private ?string $clientMediaType;
111
+
112
+	/**
113
+	 * Constructor of the class
114
+	 *
115
+	 * @param StreamInterface $stream
116
+	 * @param int|null $size
117
+	 * @param int $error
118
+	 * @param string|null $clientFilename
119
+	 * @param string|null $clientMediaType
120
+	 */
121
+	public function __construct(
122
+		StreamInterface $stream,
123
+		?int $size = null,
124
+		int $error = UPLOAD_ERR_OK,
125
+		?string $clientFilename = null,
126
+		?string $clientMediaType = null
127
+	) {
128
+		if (UPLOAD_ERR_OK === $error) {
129
+			$this->stream = $stream;
130
+		}
131
+
132
+		$message = self::UPLOAD_ERRORS[$error] ?? 'Unknown error';
133
+
134
+		$this->size = $size;
135
+		$this->errorCode = $error;
136
+		$this->errorMessage = $message;
137
+		$this->clientFilename = $clientFilename;
138
+		$this->clientMediaType = $clientMediaType;
139
+	}
140
+
141
+	/**
142
+	 * Gets the file stream
143
+	 *
144
+	 * @return StreamInterface
145
+	 *
146
+	 * @throws RuntimeException
147
+	 *         - If the file has no a stream due to an error;
148
+	 *         - If the file was already moved.
149
+	 */
150
+	public function getStream(): StreamInterface
151
+	{
152
+		if (UPLOAD_ERR_OK <> $this->errorCode) {
153
+			throw new RuntimeException(sprintf(
154
+				'Uploaded file has no a stream due to the error #%d (%s)',
155
+				$this->errorCode,
156
+				$this->errorMessage
157
+			));
158
+		}
159
+
160
+		if (!isset($this->stream)) {
161
+			throw new RuntimeException(
162
+				'Uploaded file has no a stream because it was already moved'
163
+			);
164
+		}
165
+
166
+		return $this->stream;
167
+	}
168
+
169
+	/**
170
+	 * Moves the file to the given path
171
+	 *
172
+	 * @param string $targetPath
173
+	 *
174
+	 * @return void
175
+	 *
176
+	 * @throws RuntimeException
177
+	 *         - If the file has no a stream due to an error;
178
+	 *         - If the file was already moved;
179
+	 *         - If the file cannot be read;
180
+	 *         - If the target path cannot be used.
181
+	 */
182
+	public function moveTo($targetPath): void
183
+	{
184
+		if (UPLOAD_ERR_OK <> $this->errorCode) {
185
+			throw new RuntimeException(sprintf(
186
+				'Uploaded file cannot be moved due to the error #%d (%s)',
187
+				$this->errorCode,
188
+				$this->errorMessage
189
+			));
190
+		}
191
+
192
+		if (!isset($this->stream)) {
193
+			throw new RuntimeException(
194
+				'Uploaded file cannot be moved because it was already moved'
195
+			);
196
+		}
197
+
198
+		if (!$this->stream->isReadable()) {
199
+			throw new RuntimeException(
200
+				'Uploaded file cannot be moved because it is not readable'
201
+			);
202
+		}
203
+
204
+		$targetDir = dirname($targetPath);
205
+		if (!is_dir($targetDir) || !is_writable($targetDir)) {
206
+			throw new RuntimeException(sprintf(
207
+				'Uploaded file cannot be moved because the directory "%s" is not writable',
208
+				$targetDir
209
+			));
210
+		}
211
+
212
+		$targetStream = new FileStream($targetPath, 'wb');
213
+
214
+		if ($this->stream->isSeekable()) {
215
+			$this->stream->rewind();
216
+		}
217
+
218
+		while (!$this->stream->eof()) {
219
+			$targetStream->write(
220
+				$this->stream->read(4096)
221
+			);
222
+		}
223
+
224
+		$targetStream->close();
225
+
226
+		/** @var string|null */
227
+		$sourcePath = $this->stream->getMetadata('uri');
228
+
229
+		$this->stream->close();
230
+		$this->stream = null;
231
+
232
+		if (isset($sourcePath) && is_file($sourcePath)) {
233
+			$sourceDir = dirname($sourcePath);
234
+			if (is_writable($sourceDir)) {
235
+				unlink($sourcePath);
236
+			}
237
+		}
238
+	}
239
+
240
+	/**
241
+	 * Gets the file size
242
+	 *
243
+	 * @return int|null
244
+	 */
245
+	public function getSize(): ?int
246
+	{
247
+		return $this->size;
248
+	}
249
+
250
+	/**
251
+	 * Gets the file's error code
252
+	 *
253
+	 * @return int
254
+	 */
255
+	public function getError(): int
256
+	{
257
+		return $this->errorCode;
258
+	}
259
+
260
+	/**
261
+	 * Gets the client's file name
262
+	 *
263
+	 * @return string|null
264
+	 */
265
+	public function getClientFilename(): ?string
266
+	{
267
+		return $this->clientFilename;
268
+	}
269
+
270
+	/**
271
+	 * Gets the client's file media type
272
+	 *
273
+	 * @return string|null
274
+	 */
275
+	public function getClientMediaType(): ?string
276
+	{
277
+		return $this->clientMediaType;
278
+	}
279 279
 }
Please login to merge, or discard this patch.