Skip to content

Commit 7889548

Browse files
committed
feat: stringable coder
1 parent 70f9d51 commit 7889548

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

src/Coder.php

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace PetrKnap\Binary;
66

77
use PetrKnap\Shorts\Exception;
8+
use Stringable;
89

910
/**
1011
* @internal please use subclass
@@ -13,10 +14,13 @@
1314
*
1415
* @implements CoderInterface<Exception\CouldNotProcessData>
1516
*/
16-
abstract class Coder implements CoderInterface
17+
abstract class Coder implements CoderInterface, Stringable
1718
{
18-
public function __construct(
19-
protected readonly string $data = '',
19+
/**
20+
* @param string $data may contain binary data
21+
*/
22+
final public function __construct(
23+
public readonly string $data = '',
2024
) {
2125
}
2226

@@ -25,7 +29,18 @@ public function withData(string $data): static
2529
return static::create($this, $data);
2630
}
2731

28-
public function getData(): string
32+
/**
33+
* @deprecated use readonly property {@see self::$data}
34+
*/
35+
final public function getData(): string
36+
{
37+
return $this->data;
38+
}
39+
40+
/**
41+
* @note this is just a helper, this class is not supposed to implement {@see BinariableInterface}
42+
*/
43+
public function __toString(): string
2944
{
3045
return $this->data;
3146
}

0 commit comments

Comments
 (0)