@@ -22,10 +22,10 @@ private function __construct(
22
22
) {
23
23
}
24
24
25
- public static function tryFromEncoded (Stringable |string $ encodedValue ): ?self
25
+ public static function tryFromEncoded (Stringable |string $ encoded ): ?self
26
26
{
27
27
try {
28
- return self ::fromEncoded ($ encodedValue );
28
+ return self ::fromEncoded ($ encoded );
29
29
} catch (Throwable ) {
30
30
return null ;
31
31
}
@@ -34,41 +34,41 @@ public static function tryFromEncoded(Stringable|string $encodedValue): ?self
34
34
/**
35
35
* Returns a new instance from a Base64 encoded string.
36
36
*/
37
- public static function fromEncoded (Stringable |string $ encodedValue ): self
37
+ public static function fromEncoded (Stringable |string $ encoded ): self
38
38
{
39
- $ value = (string ) $ encodedValue ;
39
+ $ encoded = (string ) $ encoded ;
40
40
41
- if (1 === preg_match ('/[^\x20-\x7E]/i ' , $ value )) {
42
- throw new SyntaxError ('The string contains invalid characters. ' . $ value );
41
+ if (1 === preg_match ('/[^\x20-\x7E]/i ' , $ encoded )) {
42
+ throw new SyntaxError ('The display string ' . $ encoded . ' contains invalid characters. ' );
43
43
}
44
44
45
- if (!str_contains ($ value , '% ' )) {
46
- return new self ($ value );
45
+ if (!str_contains ($ encoded , '% ' )) {
46
+ return new self ($ encoded );
47
47
}
48
48
49
- if (1 === preg_match ('/%(?![0-9a-f]{2})/ ' , $ value )) {
50
- throw new SyntaxError ('The string ' .$ value .' contains invalid utf-8 encoded sequence. ' );
49
+ if (1 === preg_match ('/%(?![0-9a-f]{2})/ ' , $ encoded )) {
50
+ throw new SyntaxError ('The display string ' .$ encoded .' contains invalid utf-8 encoded sequence. ' );
51
51
}
52
52
53
- $ value = (string ) preg_replace_callback (
53
+ $ decoded = (string ) preg_replace_callback (
54
54
',%[a-f0-9]{2}, ' ,
55
55
fn (array $ matches ): string => rawurldecode ($ matches [0 ]),
56
- $ value
56
+ $ encoded
57
57
);
58
58
59
- if (1 !== preg_match ('//u ' , $ value )) {
60
- throw new SyntaxError ('The string contains invalid characters. ' . $ value );
59
+ if (1 !== preg_match ('//u ' , $ decoded )) {
60
+ throw new SyntaxError ('The display string ' . $ encoded . ' contains invalid characters. ' );
61
61
}
62
62
63
- return new self ($ value );
63
+ return new self ($ decoded );
64
64
}
65
65
66
66
/**
67
67
* Returns a new instance from a raw decoded string.
68
68
*/
69
- public static function fromDecoded (Stringable |string $ value ): self
69
+ public static function fromDecoded (Stringable |string $ decoded ): self
70
70
{
71
- return new self ((string ) $ value );
71
+ return new self ((string ) $ decoded );
72
72
}
73
73
74
74
/**
0 commit comments