Passed
Pull Request — master (#31)
by Anatoly
39:30
created
src/Header/ContentTypeHeader.php 1 patch
Indentation   +52 added lines, -52 removed lines patch added patch discarded remove patch
@@ -28,64 +28,64 @@
 block discarded – undo
28 28
 class ContentTypeHeader extends Header
29 29
 {
30 30
 
31
-    /**
32
-     * Regular Expression for a content type validation
33
-     *
34
-     * @link https://tools.ietf.org/html/rfc6838#section-4.2
35
-     *
36
-     * @var string
37
-     */
38
-    public const RFC6838_CONTENT_TYPE = '/^[\dA-Za-z][\d\w\!#\$&\+\-\.\^]*(?:\/[\dA-Za-z][\d\w\!#\$&\+\-\.\^]*)?$/';
31
+	/**
32
+	 * Regular Expression for a content type validation
33
+	 *
34
+	 * @link https://tools.ietf.org/html/rfc6838#section-4.2
35
+	 *
36
+	 * @var string
37
+	 */
38
+	public const RFC6838_CONTENT_TYPE = '/^[\dA-Za-z][\d\w\!#\$&\+\-\.\^]*(?:\/[\dA-Za-z][\d\w\!#\$&\+\-\.\^]*)?$/';
39 39
 
40
-    /**
41
-     * @var string
42
-     */
43
-    private string $type;
40
+	/**
41
+	 * @var string
42
+	 */
43
+	private string $type;
44 44
 
45
-    /**
46
-     * @var array<string, string>
47
-     */
48
-    private array $parameters;
45
+	/**
46
+	 * @var array<string, string>
47
+	 */
48
+	private array $parameters;
49 49
 
50
-    /**
51
-     * Constructor of the class
52
-     *
53
-     * @param string $type
54
-     * @param array<array-key, mixed> $parameters
55
-     *
56
-     * @throws InvalidHeaderException
57
-     *         - If the type isn't valid;
58
-     *         - If the parameters aren't valid.
59
-     */
60
-    public function __construct(string $type, array $parameters = [])
61
-    {
62
-        $this->validateValueByRegex(self::RFC6838_CONTENT_TYPE, $type);
50
+	/**
51
+	 * Constructor of the class
52
+	 *
53
+	 * @param string $type
54
+	 * @param array<array-key, mixed> $parameters
55
+	 *
56
+	 * @throws InvalidHeaderException
57
+	 *         - If the type isn't valid;
58
+	 *         - If the parameters aren't valid.
59
+	 */
60
+	public function __construct(string $type, array $parameters = [])
61
+	{
62
+		$this->validateValueByRegex(self::RFC6838_CONTENT_TYPE, $type);
63 63
 
64
-        // validate and normalize the parameters...
65
-        $parameters = $this->validateParameters($parameters);
64
+		// validate and normalize the parameters...
65
+		$parameters = $this->validateParameters($parameters);
66 66
 
67
-        $this->type = $type;
68
-        $this->parameters = $parameters;
69
-    }
67
+		$this->type = $type;
68
+		$this->parameters = $parameters;
69
+	}
70 70
 
71
-    /**
72
-     * {@inheritdoc}
73
-     */
74
-    public function getFieldName(): string
75
-    {
76
-        return 'Content-Type';
77
-    }
71
+	/**
72
+	 * {@inheritdoc}
73
+	 */
74
+	public function getFieldName(): string
75
+	{
76
+		return 'Content-Type';
77
+	}
78 78
 
79
-    /**
80
-     * {@inheritdoc}
81
-     */
82
-    public function getFieldValue(): string
83
-    {
84
-        $v = $this->type;
85
-        foreach ($this->parameters as $name => $value) {
86
-            $v .= sprintf('; %s="%s"', $name, $value);
87
-        }
79
+	/**
80
+	 * {@inheritdoc}
81
+	 */
82
+	public function getFieldValue(): string
83
+	{
84
+		$v = $this->type;
85
+		foreach ($this->parameters as $name => $value) {
86
+			$v .= sprintf('; %s="%s"', $name, $value);
87
+		}
88 88
 
89
-        return $v;
90
-    }
89
+		return $v;
90
+	}
91 91
 }
Please login to merge, or discard this patch.
src/Header/ContentLengthHeader.php 2 patches
Indentation   +51 added lines, -51 removed lines patch added patch discarded remove patch
@@ -28,60 +28,60 @@
 block discarded – undo
28 28
 class ContentLengthHeader extends Header
29 29
 {
30 30
 
31
-    /**
32
-     * @var int
33
-     */
34
-    private int $value;
31
+	/**
32
+	 * @var int
33
+	 */
34
+	private int $value;
35 35
 
36
-    /**
37
-     * Constructor of the class
38
-     *
39
-     * @param int $value
40
-     *
41
-     * @throws InvalidHeaderException
42
-     *         If the value isn't valid.
43
-     */
44
-    public function __construct(int $value)
45
-    {
46
-        $this->validateValue($value);
36
+	/**
37
+	 * Constructor of the class
38
+	 *
39
+	 * @param int $value
40
+	 *
41
+	 * @throws InvalidHeaderException
42
+	 *         If the value isn't valid.
43
+	 */
44
+	public function __construct(int $value)
45
+	{
46
+		$this->validateValue($value);
47 47
 
48
-        $this->value = $value;
49
-    }
48
+		$this->value = $value;
49
+	}
50 50
 
51
-    /**
52
-     * {@inheritdoc}
53
-     */
54
-    public function getFieldName(): string
55
-    {
56
-        return 'Content-Length';
57
-    }
51
+	/**
52
+	 * {@inheritdoc}
53
+	 */
54
+	public function getFieldName(): string
55
+	{
56
+		return 'Content-Length';
57
+	}
58 58
 
59
-    /**
60
-     * {@inheritdoc}
61
-     */
62
-    public function getFieldValue(): string
63
-    {
64
-        return sprintf('%d', $this->value);
65
-    }
59
+	/**
60
+	 * {@inheritdoc}
61
+	 */
62
+	public function getFieldValue(): string
63
+	{
64
+		return sprintf('%d', $this->value);
65
+	}
66 66
 
67
-    /**
68
-     * Validates the given value
69
-     *
70
-     * @param int $value
71
-     *
72
-     * @return void
73
-     *
74
-     * @throws InvalidHeaderException
75
-     *         If the value isn't valid.
76
-     */
77
-    private function validateValue(int $value): void
78
-    {
79
-        if (! ($value >= 0)) {
80
-            throw new InvalidHeaderException(sprintf(
81
-                'The value "%2$d" for the header "%1$s" is not valid',
82
-                $this->getFieldName(),
83
-                $value
84
-            ));
85
-        }
86
-    }
67
+	/**
68
+	 * Validates the given value
69
+	 *
70
+	 * @param int $value
71
+	 *
72
+	 * @return void
73
+	 *
74
+	 * @throws InvalidHeaderException
75
+	 *         If the value isn't valid.
76
+	 */
77
+	private function validateValue(int $value): void
78
+	{
79
+		if (! ($value >= 0)) {
80
+			throw new InvalidHeaderException(sprintf(
81
+				'The value "%2$d" for the header "%1$s" is not valid',
82
+				$this->getFieldName(),
83
+				$value
84
+			));
85
+		}
86
+	}
87 87
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -76,7 +76,7 @@
 block discarded – undo
76 76
      */
77 77
     private function validateValue(int $value): void
78 78
     {
79
-        if (! ($value >= 0)) {
79
+        if (!($value >= 0)) {
80 80
             throw new InvalidHeaderException(sprintf(
81 81
                 'The value "%2$d" for the header "%1$s" is not valid',
82 82
                 $this->getFieldName(),
Please login to merge, or discard this patch.
src/Header/RefreshHeader.php 2 patches
Indentation   +61 added lines, -61 removed lines patch added patch discarded remove patch
@@ -31,72 +31,72 @@
 block discarded – undo
31 31
 class RefreshHeader extends Header
32 32
 {
33 33
 
34
-    /**
35
-     * @var int
36
-     */
37
-    private int $delay;
34
+	/**
35
+	 * @var int
36
+	 */
37
+	private int $delay;
38 38
 
39
-    /**
40
-     * @var UriInterface
41
-     */
42
-    private UriInterface $uri;
39
+	/**
40
+	 * @var UriInterface
41
+	 */
42
+	private UriInterface $uri;
43 43
 
44
-    /**
45
-     * Constructor of the class
46
-     *
47
-     * @param int $delay
48
-     * @param mixed $uri
49
-     *
50
-     * @throws InvalidUriException
51
-     *         If the URI isn't valid.
52
-     *
53
-     * @throws InvalidHeaderException
54
-     *         If the delay isn't valid.
55
-     */
56
-    public function __construct(int $delay, $uri)
57
-    {
58
-        $this->validateDelay($delay);
44
+	/**
45
+	 * Constructor of the class
46
+	 *
47
+	 * @param int $delay
48
+	 * @param mixed $uri
49
+	 *
50
+	 * @throws InvalidUriException
51
+	 *         If the URI isn't valid.
52
+	 *
53
+	 * @throws InvalidHeaderException
54
+	 *         If the delay isn't valid.
55
+	 */
56
+	public function __construct(int $delay, $uri)
57
+	{
58
+		$this->validateDelay($delay);
59 59
 
60
-        $uri = Uri::create($uri);
60
+		$uri = Uri::create($uri);
61 61
 
62
-        $this->delay = $delay;
63
-        $this->uri = $uri;
64
-    }
62
+		$this->delay = $delay;
63
+		$this->uri = $uri;
64
+	}
65 65
 
66
-    /**
67
-     * {@inheritdoc}
68
-     */
69
-    public function getFieldName(): string
70
-    {
71
-        return 'Refresh';
72
-    }
66
+	/**
67
+	 * {@inheritdoc}
68
+	 */
69
+	public function getFieldName(): string
70
+	{
71
+		return 'Refresh';
72
+	}
73 73
 
74
-    /**
75
-     * {@inheritdoc}
76
-     */
77
-    public function getFieldValue(): string
78
-    {
79
-        return sprintf('%d; url=%s', $this->delay, $this->uri->__toString());
80
-    }
74
+	/**
75
+	 * {@inheritdoc}
76
+	 */
77
+	public function getFieldValue(): string
78
+	{
79
+		return sprintf('%d; url=%s', $this->delay, $this->uri->__toString());
80
+	}
81 81
 
82
-    /**
83
-     * Validates the redirection delay
84
-     *
85
-     * @param int $delay
86
-     *
87
-     * @return void
88
-     *
89
-     * @throws InvalidHeaderException
90
-     *         If the delay isn't valid.
91
-     */
92
-    private function validateDelay(int $delay): void
93
-    {
94
-        if (! ($delay >= 0)) {
95
-            throw new InvalidHeaderException(sprintf(
96
-                'The delay "%2$d" for the header "%1$s" is not valid',
97
-                $this->getFieldName(),
98
-                $delay
99
-            ));
100
-        }
101
-    }
82
+	/**
83
+	 * Validates the redirection delay
84
+	 *
85
+	 * @param int $delay
86
+	 *
87
+	 * @return void
88
+	 *
89
+	 * @throws InvalidHeaderException
90
+	 *         If the delay isn't valid.
91
+	 */
92
+	private function validateDelay(int $delay): void
93
+	{
94
+		if (! ($delay >= 0)) {
95
+			throw new InvalidHeaderException(sprintf(
96
+				'The delay "%2$d" for the header "%1$s" is not valid',
97
+				$this->getFieldName(),
98
+				$delay
99
+			));
100
+		}
101
+	}
102 102
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -91,7 +91,7 @@
 block discarded – undo
91 91
      */
92 92
     private function validateDelay(int $delay): void
93 93
     {
94
-        if (! ($delay >= 0)) {
94
+        if (!($delay >= 0)) {
95 95
             throw new InvalidHeaderException(sprintf(
96 96
                 'The delay "%2$d" for the header "%1$s" is not valid',
97 97
                 $this->getFieldName(),
Please login to merge, or discard this patch.
src/Header/ContentMD5Header.php 1 patch
Indentation   +39 added lines, -39 removed lines patch added patch discarded remove patch
@@ -23,48 +23,48 @@
 block discarded – undo
23 23
 class ContentMD5Header extends Header
24 24
 {
25 25
 
26
-    /**
27
-     * Regular Expression for a MD5 digest validation
28
-     *
29
-     * @link https://tools.ietf.org/html/rfc2045#section-6.8
30
-     *
31
-     * @var string
32
-     */
33
-    public const RFC2045_MD5_DIGEST = '/^[A-Za-z0-9\+\/]+=*$/';
26
+	/**
27
+	 * Regular Expression for a MD5 digest validation
28
+	 *
29
+	 * @link https://tools.ietf.org/html/rfc2045#section-6.8
30
+	 *
31
+	 * @var string
32
+	 */
33
+	public const RFC2045_MD5_DIGEST = '/^[A-Za-z0-9\+\/]+=*$/';
34 34
 
35
-    /**
36
-     * @var string
37
-     */
38
-    private string $value;
35
+	/**
36
+	 * @var string
37
+	 */
38
+	private string $value;
39 39
 
40
-    /**
41
-     * Constructor of the class
42
-     *
43
-     * @param string $value
44
-     *
45
-     * @throws InvalidHeaderException
46
-     *         If the value isn't valid.
47
-     */
48
-    public function __construct(string $value)
49
-    {
50
-        $this->validateValueByRegex(self::RFC2045_MD5_DIGEST, $value);
40
+	/**
41
+	 * Constructor of the class
42
+	 *
43
+	 * @param string $value
44
+	 *
45
+	 * @throws InvalidHeaderException
46
+	 *         If the value isn't valid.
47
+	 */
48
+	public function __construct(string $value)
49
+	{
50
+		$this->validateValueByRegex(self::RFC2045_MD5_DIGEST, $value);
51 51
 
52
-        $this->value = $value;
53
-    }
52
+		$this->value = $value;
53
+	}
54 54
 
55
-    /**
56
-     * {@inheritdoc}
57
-     */
58
-    public function getFieldName(): string
59
-    {
60
-        return 'Content-MD5';
61
-    }
55
+	/**
56
+	 * {@inheritdoc}
57
+	 */
58
+	public function getFieldName(): string
59
+	{
60
+		return 'Content-MD5';
61
+	}
62 62
 
63
-    /**
64
-     * {@inheritdoc}
65
-     */
66
-    public function getFieldValue(): string
67
-    {
68
-        return $this->value;
69
-    }
63
+	/**
64
+	 * {@inheritdoc}
65
+	 */
66
+	public function getFieldValue(): string
67
+	{
68
+		return $this->value;
69
+	}
70 70
 }
Please login to merge, or discard this patch.
src/Header/AccessControlAllowMethodsHeader.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 AccessControlAllowMethodsHeader 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 'Access-Control-Allow-Methods';
60
-    }
54
+	/**
55
+	 * {@inheritdoc}
56
+	 */
57
+	public function getFieldName(): string
58
+	{
59
+		return 'Access-Control-Allow-Methods';
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/TrailerHeader.php 1 patch
Indentation   +35 added lines, -35 removed lines patch added patch discarded remove patch
@@ -23,39 +23,39 @@
 block discarded – undo
23 23
 class TrailerHeader extends Header
24 24
 {
25 25
 
26
-    /**
27
-     * @var string
28
-     */
29
-    private string $value;
30
-
31
-    /**
32
-     * Constructor of the class
33
-     *
34
-     * @param string $value
35
-     *
36
-     * @throws InvalidHeaderException
37
-     *         If the value isn't valid.
38
-     */
39
-    public function __construct(string $value)
40
-    {
41
-        $this->validateToken($value);
42
-
43
-        $this->value = $value;
44
-    }
45
-
46
-    /**
47
-     * {@inheritdoc}
48
-     */
49
-    public function getFieldName(): string
50
-    {
51
-        return 'Trailer';
52
-    }
53
-
54
-    /**
55
-     * {@inheritdoc}
56
-     */
57
-    public function getFieldValue(): string
58
-    {
59
-        return $this->value;
60
-    }
26
+	/**
27
+	 * @var string
28
+	 */
29
+	private string $value;
30
+
31
+	/**
32
+	 * Constructor of the class
33
+	 *
34
+	 * @param string $value
35
+	 *
36
+	 * @throws InvalidHeaderException
37
+	 *         If the value isn't valid.
38
+	 */
39
+	public function __construct(string $value)
40
+	{
41
+		$this->validateToken($value);
42
+
43
+		$this->value = $value;
44
+	}
45
+
46
+	/**
47
+	 * {@inheritdoc}
48
+	 */
49
+	public function getFieldName(): string
50
+	{
51
+		return 'Trailer';
52
+	}
53
+
54
+	/**
55
+	 * {@inheritdoc}
56
+	 */
57
+	public function getFieldValue(): string
58
+	{
59
+		return $this->value;
60
+	}
61 61
 }
Please login to merge, or discard this patch.
src/Header/AccessControlAllowHeadersHeader.php 1 patch
Indentation   +33 added lines, -33 removed lines patch added patch discarded remove patch
@@ -28,41 +28,41 @@
 block discarded – undo
28 28
 class AccessControlAllowHeadersHeader extends Header
29 29
 {
30 30
 
31
-    /**
32
-     * @var list<string>
33
-     */
34
-    private array $headers = [];
31
+	/**
32
+	 * @var list<string>
33
+	 */
34
+	private array $headers = [];
35 35
 
36
-    /**
37
-     * Constructor of the class
38
-     *
39
-     * @param string ...$headers
40
-     *
41
-     * @throws InvalidHeaderException
42
-     *         If one of the header names isn't valid.
43
-     */
44
-    public function __construct(string ...$headers)
45
-    {
46
-        $this->validateToken(...$headers);
36
+	/**
37
+	 * Constructor of the class
38
+	 *
39
+	 * @param string ...$headers
40
+	 *
41
+	 * @throws InvalidHeaderException
42
+	 *         If one of the header names isn't valid.
43
+	 */
44
+	public function __construct(string ...$headers)
45
+	{
46
+		$this->validateToken(...$headers);
47 47
 
48
-        foreach ($headers as $header) {
49
-            $this->headers[] = $header;
50
-        }
51
-    }
48
+		foreach ($headers as $header) {
49
+			$this->headers[] = $header;
50
+		}
51
+	}
52 52
 
53
-    /**
54
-     * {@inheritdoc}
55
-     */
56
-    public function getFieldName(): string
57
-    {
58
-        return 'Access-Control-Allow-Headers';
59
-    }
53
+	/**
54
+	 * {@inheritdoc}
55
+	 */
56
+	public function getFieldName(): string
57
+	{
58
+		return 'Access-Control-Allow-Headers';
59
+	}
60 60
 
61
-    /**
62
-     * {@inheritdoc}
63
-     */
64
-    public function getFieldValue(): string
65
-    {
66
-        return implode(', ', $this->headers);
67
-    }
61
+	/**
62
+	 * {@inheritdoc}
63
+	 */
64
+	public function getFieldValue(): string
65
+	{
66
+		return implode(', ', $this->headers);
67
+	}
68 68
 }
Please login to merge, or discard this patch.
src/Header/SetCookieHeader.php 2 patches
Indentation   +249 added lines, -249 removed lines patch added patch discarded remove patch
@@ -36,253 +36,253 @@
 block discarded – undo
36 36
 class SetCookieHeader extends Header
37 37
 {
38 38
 
39
-    /**
40
-     * Default cookie options
41
-     *
42
-     * @var array{
43
-     *   path?: ?string,
44
-     *   domain?: ?string,
45
-     *   secure?: ?bool,
46
-     *   httpOnly?: ?bool,
47
-     *   sameSite?: ?string
48
-     * }
49
-     */
50
-    public const DEFAULT_OPTIONS = [
51
-        self::OPTION_KEY_PATH      => '/',
52
-        self::OPTION_KEY_DOMAIN    => null,
53
-        self::OPTION_KEY_SECURE    => null,
54
-        self::OPTION_KEY_HTTP_ONLY => true,
55
-        self::OPTION_KEY_SAME_SITE => CookieSameSite::LAX,
56
-    ];
57
-
58
-    /**
59
-     * Cookie option keys
60
-     */
61
-    public const OPTION_KEY_PATH = 'path';
62
-    public const OPTION_KEY_DOMAIN = 'domain';
63
-    public const OPTION_KEY_SECURE = 'secure';
64
-    public const OPTION_KEY_HTTP_ONLY = 'httpOnly';
65
-    public const OPTION_KEY_SAME_SITE = 'sameSite';
66
-
67
-    /**
68
-     * @deprecated Use the {@see CookieSameSite} enum.
69
-     */
70
-    public const SAME_SITE_LAX = CookieSameSite::LAX;
71
-
72
-    /**
73
-     * @deprecated Use the {@see CookieSameSite} enum.
74
-     */
75
-    public const SAME_SITE_STRICT = CookieSameSite::STRICT;
76
-
77
-    /**
78
-     * @deprecated Use the {@see CookieSameSite} enum.
79
-     */
80
-    public const SAME_SITE_NONE = CookieSameSite::NONE;
81
-
82
-    /**
83
-     * @deprecated Use the {@see SetCookieHeader::OPTION_KEY_SAME_SITE} constant.
84
-     */
85
-    public const OPTION_KEY_SAMESITE = self::OPTION_KEY_SAME_SITE;
86
-
87
-    /**
88
-     * @var ?array{
89
-     *   path?: ?string,
90
-     *   domain?: ?string,
91
-     *   secure?: ?bool,
92
-     *   httpOnly?: ?bool,
93
-     *   sameSite?: ?string
94
-     * }
95
-     *
96
-     * @deprecated Use the {@see SetCookieHeader::DEFAULT_OPTIONS} constant.
97
-     */
98
-    protected static ?array $defaultOptions = null;
99
-
100
-    /**
101
-     * The cookie name
102
-     *
103
-     * @var string
104
-     */
105
-    private string $name;
106
-
107
-    /**
108
-     * The cookie value
109
-     *
110
-     * @var string
111
-     */
112
-    private string $value;
113
-
114
-    /**
115
-     * The cookie expiration date
116
-     *
117
-     * @var DateTimeInterface|null
118
-     */
119
-    private ?DateTimeInterface $expires;
120
-
121
-    /**
122
-     * The cookie options
123
-     *
124
-     * @var array{
125
-     *   path?: ?string,
126
-     *   domain?: ?string,
127
-     *   secure?: ?bool,
128
-     *   httpOnly?: ?bool,
129
-     *   sameSite?: ?string
130
-     * }
131
-     */
132
-    private array $options;
133
-
134
-    /**
135
-     * Constructor of the class
136
-     *
137
-     * @param string $name
138
-     * @param string $value
139
-     * @param DateTimeInterface|null $expires
140
-     * @param array{
141
-     *   path?: ?string,
142
-     *   domain?: ?string,
143
-     *   secure?: ?bool,
144
-     *   httpOnly?: ?bool,
145
-     *   sameSite?: ?string
146
-     * } $options
147
-     *
148
-     * @throws InvalidHeaderException
149
-     *         If one of the arguments isn't valid.
150
-     */
151
-    public function __construct(string $name, string $value, ?DateTimeInterface $expires = null, array $options = [])
152
-    {
153
-        $this->validateCookieName($name);
154
-
155
-        if (isset($options[self::OPTION_KEY_PATH])) {
156
-            $this->validateCookieOption(
157
-                self::OPTION_KEY_PATH,
158
-                $options[self::OPTION_KEY_PATH]
159
-            );
160
-        }
161
-
162
-        if (isset($options[self::OPTION_KEY_DOMAIN])) {
163
-            $this->validateCookieOption(
164
-                self::OPTION_KEY_DOMAIN,
165
-                $options[self::OPTION_KEY_DOMAIN]
166
-            );
167
-        }
168
-
169
-        if (isset($options[self::OPTION_KEY_SAME_SITE])) {
170
-            $this->validateCookieOption(
171
-                self::OPTION_KEY_SAME_SITE,
172
-                $options[self::OPTION_KEY_SAME_SITE]
173
-            );
174
-        }
175
-
176
-        if ($value === '') {
177
-            $value = 'deleted';
178
-            $expires = new DateTimeImmutable('1 year ago');
179
-        }
180
-
181
-        $options += (static::$defaultOptions ?? static::DEFAULT_OPTIONS);
182
-
183
-        $this->name = $name;
184
-        $this->value = $value;
185
-        $this->expires = $expires;
186
-        $this->options = $options;
187
-    }
188
-
189
-    /**
190
-     * {@inheritdoc}
191
-     */
192
-    public function getFieldName(): string
193
-    {
194
-        return 'Set-Cookie';
195
-    }
196
-
197
-    /**
198
-     * {@inheritdoc}
199
-     */
200
-    public function getFieldValue(): string
201
-    {
202
-        $name = rawurlencode($this->name);
203
-        $value = rawurlencode($this->value);
204
-        $result = sprintf('%s=%s', $name, $value);
205
-
206
-        if (isset($this->expires)) {
207
-            $result .= '; Expires=' . $this->formatDateTime($this->expires);
208
-            $result .= '; Max-Age=' . max($this->expires->getTimestamp() - time(), 0);
209
-        }
210
-
211
-        if (isset($this->options[self::OPTION_KEY_PATH])) {
212
-            $result .= '; Path=' . $this->options[self::OPTION_KEY_PATH];
213
-        }
214
-
215
-        if (isset($this->options[self::OPTION_KEY_DOMAIN])) {
216
-            $result .= '; Domain=' . $this->options[self::OPTION_KEY_DOMAIN];
217
-        }
218
-
219
-        if (isset($this->options[self::OPTION_KEY_SECURE]) && $this->options[self::OPTION_KEY_SECURE]) {
220
-            $result .= '; Secure';
221
-        }
222
-
223
-        if (isset($this->options[self::OPTION_KEY_HTTP_ONLY]) && $this->options[self::OPTION_KEY_HTTP_ONLY]) {
224
-            $result .= '; HttpOnly';
225
-        }
226
-
227
-        if (isset($this->options[self::OPTION_KEY_SAME_SITE])) {
228
-            $result .= '; SameSite=' . $this->options[self::OPTION_KEY_SAME_SITE];
229
-        }
230
-
231
-        return $result;
232
-    }
233
-
234
-    /**
235
-     * Validates the given cookie name
236
-     *
237
-     * @param string $name
238
-     *
239
-     * @return void
240
-     *
241
-     * @throws InvalidHeaderException
242
-     *         If the cookie name isn't valid.
243
-     */
244
-    private function validateCookieName(string $name): void
245
-    {
246
-        if ('' === $name) {
247
-            throw new InvalidHeaderException('Cookie name cannot be empty');
248
-        }
249
-
250
-        // https://github.com/php/php-src/blob/02a5335b710aa36cd0c3108bfb9c6f7a57d40000/ext/standard/head.c#L93
251
-        if (strpbrk($name, "=,; \t\r\n\013\014") !== false) {
252
-            throw new InvalidHeaderException(sprintf(
253
-                'The cookie name "%s" contains prohibited characters',
254
-                $name
255
-            ));
256
-        }
257
-    }
258
-
259
-    /**
260
-     * Validates the given cookie option
261
-     *
262
-     * @param string $key
263
-     * @param mixed $value
264
-     *
265
-     * @return void
266
-     *
267
-     * @throws InvalidHeaderException
268
-     *         If the cookie option isn't valid.
269
-     */
270
-    private function validateCookieOption(string $key, $value): void
271
-    {
272
-        if (!is_string($value)) {
273
-            throw new InvalidHeaderException(sprintf(
274
-                'The cookie option "%s" must be a string',
275
-                $key
276
-            ));
277
-        }
278
-
279
-        // https://github.com/php/php-src/blob/02a5335b710aa36cd0c3108bfb9c6f7a57d40000/ext/standard/head.c#L103
280
-        // https://github.com/php/php-src/blob/02a5335b710aa36cd0c3108bfb9c6f7a57d40000/ext/standard/head.c#L108
281
-        if (strpbrk($value, ",; \t\r\n\013\014") !== false) {
282
-            throw new InvalidHeaderException(sprintf(
283
-                'The cookie option "%s" contains prohibited characters',
284
-                $key
285
-            ));
286
-        }
287
-    }
39
+	/**
40
+	 * Default cookie options
41
+	 *
42
+	 * @var array{
43
+	 *   path?: ?string,
44
+	 *   domain?: ?string,
45
+	 *   secure?: ?bool,
46
+	 *   httpOnly?: ?bool,
47
+	 *   sameSite?: ?string
48
+	 * }
49
+	 */
50
+	public const DEFAULT_OPTIONS = [
51
+		self::OPTION_KEY_PATH      => '/',
52
+		self::OPTION_KEY_DOMAIN    => null,
53
+		self::OPTION_KEY_SECURE    => null,
54
+		self::OPTION_KEY_HTTP_ONLY => true,
55
+		self::OPTION_KEY_SAME_SITE => CookieSameSite::LAX,
56
+	];
57
+
58
+	/**
59
+	 * Cookie option keys
60
+	 */
61
+	public const OPTION_KEY_PATH = 'path';
62
+	public const OPTION_KEY_DOMAIN = 'domain';
63
+	public const OPTION_KEY_SECURE = 'secure';
64
+	public const OPTION_KEY_HTTP_ONLY = 'httpOnly';
65
+	public const OPTION_KEY_SAME_SITE = 'sameSite';
66
+
67
+	/**
68
+	 * @deprecated Use the {@see CookieSameSite} enum.
69
+	 */
70
+	public const SAME_SITE_LAX = CookieSameSite::LAX;
71
+
72
+	/**
73
+	 * @deprecated Use the {@see CookieSameSite} enum.
74
+	 */
75
+	public const SAME_SITE_STRICT = CookieSameSite::STRICT;
76
+
77
+	/**
78
+	 * @deprecated Use the {@see CookieSameSite} enum.
79
+	 */
80
+	public const SAME_SITE_NONE = CookieSameSite::NONE;
81
+
82
+	/**
83
+	 * @deprecated Use the {@see SetCookieHeader::OPTION_KEY_SAME_SITE} constant.
84
+	 */
85
+	public const OPTION_KEY_SAMESITE = self::OPTION_KEY_SAME_SITE;
86
+
87
+	/**
88
+	 * @var ?array{
89
+	 *   path?: ?string,
90
+	 *   domain?: ?string,
91
+	 *   secure?: ?bool,
92
+	 *   httpOnly?: ?bool,
93
+	 *   sameSite?: ?string
94
+	 * }
95
+	 *
96
+	 * @deprecated Use the {@see SetCookieHeader::DEFAULT_OPTIONS} constant.
97
+	 */
98
+	protected static ?array $defaultOptions = null;
99
+
100
+	/**
101
+	 * The cookie name
102
+	 *
103
+	 * @var string
104
+	 */
105
+	private string $name;
106
+
107
+	/**
108
+	 * The cookie value
109
+	 *
110
+	 * @var string
111
+	 */
112
+	private string $value;
113
+
114
+	/**
115
+	 * The cookie expiration date
116
+	 *
117
+	 * @var DateTimeInterface|null
118
+	 */
119
+	private ?DateTimeInterface $expires;
120
+
121
+	/**
122
+	 * The cookie options
123
+	 *
124
+	 * @var array{
125
+	 *   path?: ?string,
126
+	 *   domain?: ?string,
127
+	 *   secure?: ?bool,
128
+	 *   httpOnly?: ?bool,
129
+	 *   sameSite?: ?string
130
+	 * }
131
+	 */
132
+	private array $options;
133
+
134
+	/**
135
+	 * Constructor of the class
136
+	 *
137
+	 * @param string $name
138
+	 * @param string $value
139
+	 * @param DateTimeInterface|null $expires
140
+	 * @param array{
141
+	 *   path?: ?string,
142
+	 *   domain?: ?string,
143
+	 *   secure?: ?bool,
144
+	 *   httpOnly?: ?bool,
145
+	 *   sameSite?: ?string
146
+	 * } $options
147
+	 *
148
+	 * @throws InvalidHeaderException
149
+	 *         If one of the arguments isn't valid.
150
+	 */
151
+	public function __construct(string $name, string $value, ?DateTimeInterface $expires = null, array $options = [])
152
+	{
153
+		$this->validateCookieName($name);
154
+
155
+		if (isset($options[self::OPTION_KEY_PATH])) {
156
+			$this->validateCookieOption(
157
+				self::OPTION_KEY_PATH,
158
+				$options[self::OPTION_KEY_PATH]
159
+			);
160
+		}
161
+
162
+		if (isset($options[self::OPTION_KEY_DOMAIN])) {
163
+			$this->validateCookieOption(
164
+				self::OPTION_KEY_DOMAIN,
165
+				$options[self::OPTION_KEY_DOMAIN]
166
+			);
167
+		}
168
+
169
+		if (isset($options[self::OPTION_KEY_SAME_SITE])) {
170
+			$this->validateCookieOption(
171
+				self::OPTION_KEY_SAME_SITE,
172
+				$options[self::OPTION_KEY_SAME_SITE]
173
+			);
174
+		}
175
+
176
+		if ($value === '') {
177
+			$value = 'deleted';
178
+			$expires = new DateTimeImmutable('1 year ago');
179
+		}
180
+
181
+		$options += (static::$defaultOptions ?? static::DEFAULT_OPTIONS);
182
+
183
+		$this->name = $name;
184
+		$this->value = $value;
185
+		$this->expires = $expires;
186
+		$this->options = $options;
187
+	}
188
+
189
+	/**
190
+	 * {@inheritdoc}
191
+	 */
192
+	public function getFieldName(): string
193
+	{
194
+		return 'Set-Cookie';
195
+	}
196
+
197
+	/**
198
+	 * {@inheritdoc}
199
+	 */
200
+	public function getFieldValue(): string
201
+	{
202
+		$name = rawurlencode($this->name);
203
+		$value = rawurlencode($this->value);
204
+		$result = sprintf('%s=%s', $name, $value);
205
+
206
+		if (isset($this->expires)) {
207
+			$result .= '; Expires=' . $this->formatDateTime($this->expires);
208
+			$result .= '; Max-Age=' . max($this->expires->getTimestamp() - time(), 0);
209
+		}
210
+
211
+		if (isset($this->options[self::OPTION_KEY_PATH])) {
212
+			$result .= '; Path=' . $this->options[self::OPTION_KEY_PATH];
213
+		}
214
+
215
+		if (isset($this->options[self::OPTION_KEY_DOMAIN])) {
216
+			$result .= '; Domain=' . $this->options[self::OPTION_KEY_DOMAIN];
217
+		}
218
+
219
+		if (isset($this->options[self::OPTION_KEY_SECURE]) && $this->options[self::OPTION_KEY_SECURE]) {
220
+			$result .= '; Secure';
221
+		}
222
+
223
+		if (isset($this->options[self::OPTION_KEY_HTTP_ONLY]) && $this->options[self::OPTION_KEY_HTTP_ONLY]) {
224
+			$result .= '; HttpOnly';
225
+		}
226
+
227
+		if (isset($this->options[self::OPTION_KEY_SAME_SITE])) {
228
+			$result .= '; SameSite=' . $this->options[self::OPTION_KEY_SAME_SITE];
229
+		}
230
+
231
+		return $result;
232
+	}
233
+
234
+	/**
235
+	 * Validates the given cookie name
236
+	 *
237
+	 * @param string $name
238
+	 *
239
+	 * @return void
240
+	 *
241
+	 * @throws InvalidHeaderException
242
+	 *         If the cookie name isn't valid.
243
+	 */
244
+	private function validateCookieName(string $name): void
245
+	{
246
+		if ('' === $name) {
247
+			throw new InvalidHeaderException('Cookie name cannot be empty');
248
+		}
249
+
250
+		// https://github.com/php/php-src/blob/02a5335b710aa36cd0c3108bfb9c6f7a57d40000/ext/standard/head.c#L93
251
+		if (strpbrk($name, "=,; \t\r\n\013\014") !== false) {
252
+			throw new InvalidHeaderException(sprintf(
253
+				'The cookie name "%s" contains prohibited characters',
254
+				$name
255
+			));
256
+		}
257
+	}
258
+
259
+	/**
260
+	 * Validates the given cookie option
261
+	 *
262
+	 * @param string $key
263
+	 * @param mixed $value
264
+	 *
265
+	 * @return void
266
+	 *
267
+	 * @throws InvalidHeaderException
268
+	 *         If the cookie option isn't valid.
269
+	 */
270
+	private function validateCookieOption(string $key, $value): void
271
+	{
272
+		if (!is_string($value)) {
273
+			throw new InvalidHeaderException(sprintf(
274
+				'The cookie option "%s" must be a string',
275
+				$key
276
+			));
277
+		}
278
+
279
+		// https://github.com/php/php-src/blob/02a5335b710aa36cd0c3108bfb9c6f7a57d40000/ext/standard/head.c#L103
280
+		// https://github.com/php/php-src/blob/02a5335b710aa36cd0c3108bfb9c6f7a57d40000/ext/standard/head.c#L108
281
+		if (strpbrk($value, ",; \t\r\n\013\014") !== false) {
282
+			throw new InvalidHeaderException(sprintf(
283
+				'The cookie option "%s" contains prohibited characters',
284
+				$key
285
+			));
286
+		}
287
+	}
288 288
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -95,7 +95,7 @@
 block discarded – undo
95 95
      *
96 96
      * @deprecated Use the {@see SetCookieHeader::DEFAULT_OPTIONS} constant.
97 97
      */
98
-    protected static ?array $defaultOptions = null;
98
+    protected static ? array $defaultOptions = null;
99 99
 
100 100
     /**
101 101
      * The cookie name
Please login to merge, or discard this patch.
src/Header/ContentLanguageHeader.php 1 patch
Indentation   +41 added lines, -41 removed lines patch added patch discarded remove patch
@@ -28,50 +28,50 @@
 block discarded – undo
28 28
 class ContentLanguageHeader extends Header
29 29
 {
30 30
 
31
-    /**
32
-     * Regular Expression for a language tag validation
33
-     *
34
-     * @link https://tools.ietf.org/html/rfc2616#section-3.10
35
-     *
36
-     * @var string
37
-     */
38
-    public const RFC2616_LANGUAGE_TAG = '/^[a-zA-Z]{1,8}(?:\-[a-zA-Z]{1,8})?$/';
31
+	/**
32
+	 * Regular Expression for a language tag validation
33
+	 *
34
+	 * @link https://tools.ietf.org/html/rfc2616#section-3.10
35
+	 *
36
+	 * @var string
37
+	 */
38
+	public const RFC2616_LANGUAGE_TAG = '/^[a-zA-Z]{1,8}(?:\-[a-zA-Z]{1,8})?$/';
39 39
 
40
-    /**
41
-     * @var list<string>
42
-     */
43
-    private array $languages = [];
40
+	/**
41
+	 * @var list<string>
42
+	 */
43
+	private array $languages = [];
44 44
 
45
-    /**
46
-     * Constructor of the class
47
-     *
48
-     * @param string ...$languages
49
-     *
50
-     * @throws InvalidHeaderException
51
-     *         If one of the language codes isn't valid.
52
-     */
53
-    public function __construct(string ...$languages)
54
-    {
55
-        $this->validateValueByRegex(self::RFC2616_LANGUAGE_TAG, ...$languages);
45
+	/**
46
+	 * Constructor of the class
47
+	 *
48
+	 * @param string ...$languages
49
+	 *
50
+	 * @throws InvalidHeaderException
51
+	 *         If one of the language codes isn't valid.
52
+	 */
53
+	public function __construct(string ...$languages)
54
+	{
55
+		$this->validateValueByRegex(self::RFC2616_LANGUAGE_TAG, ...$languages);
56 56
 
57
-        foreach ($languages as $language) {
58
-            $this->languages[] = $language;
59
-        }
60
-    }
57
+		foreach ($languages as $language) {
58
+			$this->languages[] = $language;
59
+		}
60
+	}
61 61
 
62
-    /**
63
-     * {@inheritdoc}
64
-     */
65
-    public function getFieldName(): string
66
-    {
67
-        return 'Content-Language';
68
-    }
62
+	/**
63
+	 * {@inheritdoc}
64
+	 */
65
+	public function getFieldName(): string
66
+	{
67
+		return 'Content-Language';
68
+	}
69 69
 
70
-    /**
71
-     * {@inheritdoc}
72
-     */
73
-    public function getFieldValue(): string
74
-    {
75
-        return implode(', ', $this->languages);
76
-    }
70
+	/**
71
+	 * {@inheritdoc}
72
+	 */
73
+	public function getFieldValue(): string
74
+	{
75
+		return implode(', ', $this->languages);
76
+	}
77 77
 }
Please login to merge, or discard this patch.