44
55namespace PetrKnap \Binary ;
66
7- use PetrKnap \Shorts \Exception ;
87use Stringable ;
98
109/**
11- * @internal please use subclass
12- *
13- * @phpstan-consistent-constructor override {@see self::create()} if not
14- *
15- * @implements CoderInterface<Exception\CouldNotProcessData>
10+ * @internal shared logic
1611 */
17- abstract class Coder implements CoderInterface, Stringable
12+ abstract class Coder implements Stringable
1813{
1914 /**
2015 * @param string $data may contain binary data
2116 */
22- public function __construct (
17+ final public function __construct (
2318 public readonly string $ data = '' ,
2419 ) {
2520 }
2621
27- public function withData (string $ data ): static
22+ final public function withData (string $ data ): static
2823 {
29- return static :: create ( $ this , $ data );
24+ return new static ( $ data );
3025 }
3126
3227 /**
33- * @deprecated use readonly property {@see self::$data}
28+ * @see Coder\Base64
29+ *
30+ * @throws Coder\Exception\CoderException
3431 */
35- final public function getData (): string
36- {
37- return $ this ->data ;
38- }
32+ abstract public function base64 (): static ;
33+
34+ /**
35+ * @see Coder\Checksum
36+ *
37+ * @throws Coder\Exception\CoderException
38+ */
39+ abstract public function checksum (string |null $ algorithm = null ): static ;
40+
41+ /**
42+ * @see Coder\Hex
43+ *
44+ * @throws Coder\Exception\CoderException
45+ */
46+ abstract public function hex (): static ;
47+
48+ /**
49+ * @see Coder\Xz
50+ *
51+ * @throws Coder\Exception\CoderException
52+ */
53+ abstract public function xz (): static ;
54+
55+ /**
56+ * @see Coder\zlib
57+ *
58+ * @throws Coder\Exception\CoderException
59+ */
60+ abstract public function zlib (): static ;
3961
4062 /**
4163 * @note this is just a helper, this class is not supposed to implement {@see BinariableInterface}
@@ -44,9 +66,4 @@ public function __toString(): string
4466 {
4567 return $ this ->data ;
4668 }
47-
48- protected static function create (self $ coder , string $ data ): static
49- {
50- return new static ($ data );
51- }
5269}
0 commit comments