@@ -40,14 +40,9 @@ public function setNonce(Nonce $nonce): Policy
4040 return $ this ;
4141 }
4242
43- public function isReportOnly (): bool
44- {
45- return $ this ->reportOnly ;
46- }
47-
4843 public function getSecurityHeaderKey (): string
4944 {
50- if ($ this ->isReportOnly () ) {
45+ if ($ this ->reportOnly ) {
5146 return self ::SECURITY_HEADER_KEY_REPORT_ONLY ;
5247 }
5348
@@ -59,10 +54,16 @@ public function getDirectives(): array
5954 return $ this ->directives ;
6055 }
6156
57+ public function hasNonceDirectiveValue (): bool
58+ {
59+ return $ this ->hasNonceDirectiveValue ;
60+ }
61+
6262 /**
63+ * @param string[] $values
6364 * @throws InvalidDirectiveException
6465 */
65- public function addDirective (string $ directive , $ values ): self
66+ public function addDirective (string $ directive , array $ values ): self
6667 {
6768 if (! Directive::isValidDirective ($ directive )) {
6869 throw new InvalidDirectiveException ($ directive );
@@ -74,16 +75,6 @@ public function addDirective(string $directive, $values): self
7475 return $ this ;
7576 }
7677
77- public function getNonce (): Nonce
78- {
79- return $ this ->nonce ;
80- }
81-
82- public function hasNonceDirectiveValue (): bool
83- {
84- return $ this ->hasNonceDirectiveValue ;
85- }
86-
8778 public function __toString (): string
8879 {
8980 $ directives = $ this ->getDirectives ();
@@ -95,26 +86,21 @@ public function __toString(): string
9586 return "$ directive $ value " ;
9687 }, $ directives , $ keys );
9788
98- return implode ('; ' , $ items ).'; ' ;
89+ return implode ('; ' , $ items ).'; ' ;
9990 }
10091
10192 private function sanitizeValue (string $ value ): string
10293 {
103- if ($ this -> isSpecialValue ($ value )) {
94+ if (in_array ($ value, self :: SPECIAL_DIRECTIVES )) {
10495 return "' $ value' " ;
10596 }
10697
10798 if ($ value === '{nonce} ' ) {
10899 $ this ->hasNonceDirectiveValue = true ;
109100
110- return "'nonce- " .$ this ->getNonce () ->getValue ()."' " ;
101+ return "'nonce- " .$ this ->nonce ->getValue ()."' " ;
111102 }
112103
113104 return $ value ;
114105 }
115-
116- private function isSpecialValue (string $ directive ): bool
117- {
118- return in_array ($ directive , self ::SPECIAL_DIRECTIVES );
119- }
120106}
0 commit comments