@@ -22,10 +22,10 @@ private function __construct(
2222 ) {
2323 }
2424
25- public static function tryFromEncoded (Stringable |string $ encodedValue ): ?self
25+ public static function tryFromEncoded (Stringable |string $ encoded ): ?self
2626 {
2727 try {
28- return self ::fromEncoded ($ encodedValue );
28+ return self ::fromEncoded ($ encoded );
2929 } catch (Throwable ) {
3030 return null ;
3131 }
@@ -34,41 +34,41 @@ public static function tryFromEncoded(Stringable|string $encodedValue): ?self
3434 /**
3535 * Returns a new instance from a Base64 encoded string.
3636 */
37- public static function fromEncoded (Stringable |string $ encodedValue ): self
37+ public static function fromEncoded (Stringable |string $ encoded ): self
3838 {
39- $ value = (string ) $ encodedValue ;
39+ $ encoded = (string ) $ encoded ;
4040
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. ' );
4343 }
4444
45- if (!str_contains ($ value , '% ' )) {
46- return new self ($ value );
45+ if (!str_contains ($ encoded , '% ' )) {
46+ return new self ($ encoded );
4747 }
4848
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. ' );
5151 }
5252
53- $ value = (string ) preg_replace_callback (
53+ $ decoded = (string ) preg_replace_callback (
5454 ',%[a-f0-9]{2}, ' ,
5555 fn (array $ matches ): string => rawurldecode ($ matches [0 ]),
56- $ value
56+ $ encoded
5757 );
5858
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. ' );
6161 }
6262
63- return new self ($ value );
63+ return new self ($ decoded );
6464 }
6565
6666 /**
6767 * Returns a new instance from a raw decoded string.
6868 */
69- public static function fromDecoded (Stringable |string $ value ): self
69+ public static function fromDecoded (Stringable |string $ decoded ): self
7070 {
71- return new self ((string ) $ value );
71+ return new self ((string ) $ decoded );
7272 }
7373
7474 /**
0 commit comments