|
4 | 4 |
|
5 | 5 | namespace PetrKnap\Binary; |
6 | 6 |
|
7 | | -use PetrKnap\Shorts\Exception; |
8 | | - |
9 | 7 | /** |
10 | | - * @internal please use subclass |
11 | | - * |
12 | | - * @phpstan-consistent-constructor override {@see self::create()} if not |
13 | | - * |
14 | | - * @implements CoderInterface<Exception\CouldNotProcessData> |
| 8 | + * @internal shared logic |
15 | 9 | */ |
16 | | -abstract class Coder implements CoderInterface |
| 10 | +abstract class Coder |
17 | 11 | { |
18 | | - public function __construct( |
19 | | - protected readonly string $data = '', |
| 12 | + final public function __construct( |
| 13 | + public readonly string $data = '', |
20 | 14 | ) { |
21 | 15 | } |
22 | 16 |
|
23 | | - public function withData(string $data): static |
| 17 | + final public function withData(string $data): static |
24 | 18 | { |
25 | | - return static::create($this, $data); |
| 19 | + return new static($data); |
26 | 20 | } |
27 | 21 |
|
28 | | - public function getData(): string |
| 22 | + /** |
| 23 | + * @deprecated use readonly property $data |
| 24 | + */ |
| 25 | + final public function getData(): string |
29 | 26 | { |
30 | 27 | return $this->data; |
31 | 28 | } |
32 | 29 |
|
33 | | - protected static function create(self $coder, string $data): static |
34 | | - { |
35 | | - return new static($data); |
36 | | - } |
| 30 | + /** |
| 31 | + * @see Coder\Base64 |
| 32 | + * |
| 33 | + * @throws Coder\Exception\CoderException |
| 34 | + */ |
| 35 | + abstract public function base64(): static; |
| 36 | + |
| 37 | + /** |
| 38 | + * @see Coder\Checksum |
| 39 | + * |
| 40 | + * @throws Coder\Exception\CoderException |
| 41 | + */ |
| 42 | + abstract public function checksum(string|null $algorithm = null): static; |
| 43 | + |
| 44 | + /** |
| 45 | + * @see Coder\Hex |
| 46 | + * |
| 47 | + * @throws Coder\Exception\CoderException |
| 48 | + */ |
| 49 | + abstract public function hex(): static; |
| 50 | + |
| 51 | + /** |
| 52 | + * @see Coder\Xz |
| 53 | + * |
| 54 | + * @throws Coder\Exception\CoderException |
| 55 | + */ |
| 56 | + abstract public function xz(): static; |
| 57 | + |
| 58 | + /** |
| 59 | + * @see Coder\zlib |
| 60 | + * |
| 61 | + * @throws Coder\Exception\CoderException |
| 62 | + */ |
| 63 | + abstract public function zlib(): static; |
37 | 64 | } |
0 commit comments