1313 */
1414final class Checksum extends Coder
1515{
16- public const ALGORITHM = 'crc32 ' ;
16+ /**
17+ * @internal public for testing purposes only
18+ */
19+ public const DEFAULT_ALGORITHM = 'crc32 ' ;
1720
1821 private string $ algorithm ;
1922 private readonly Byter $ byter ;
@@ -23,15 +26,15 @@ public function __construct()
2326 $ this ->byter = new Byter ();
2427 }
2528
26- public function encode (string $ decoded , ? string $ algorithm = null ): string
29+ public function encode (string $ decoded , string | null $ algorithm = null ): string
2730 {
28- $ this ->algorithm = $ algorithm ?? self ::ALGORITHM ;
31+ $ this ->algorithm = $ algorithm ?? self ::DEFAULT_ALGORITHM ;
2932 return parent ::encode ($ decoded );
3033 }
3134
32- public function decode (string $ encoded , ? string $ algorithm = null ): string
35+ public function decode (string $ encoded , string | null $ algorithm = null ): string
3336 {
34- $ this ->algorithm = $ algorithm ?? self ::ALGORITHM ;
37+ $ this ->algorithm = $ algorithm ?? self ::DEFAULT_ALGORITHM ;
3538 return parent ::decode ($ encoded );
3639 }
3740
@@ -46,7 +49,7 @@ protected function doDecode(string $encoded): string
4649 $ checksumLength = $ this ->byter ->size (hash ($ this ->algorithm , '' , binary: true ));
4750 [,$ decoded ] = $ this ->byter ->bite ($ encoded , -$ checksumLength );
4851 if ($ this ->doEncode ($ decoded ) !== $ encoded ) {
49- throw new Exception \CouldNotDecodeData (__METHOD__ , $ encoded );
52+ throw new Exception \CoderCouldNotDecodeData (__METHOD__ , $ encoded );
5053 }
5154 return $ decoded ;
5255 }
0 commit comments