Skip to content

Commit 320283b

Browse files
committed
feat: Coder implements Stringable
1 parent 1d23cd5 commit 320283b

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

src/Coder.php

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,16 @@
44

55
namespace PetrKnap\Binary;
66

7+
use Stringable;
8+
79
/**
810
* @internal shared logic
911
*/
10-
abstract class Coder
12+
abstract class Coder implements Stringable
1113
{
14+
/**
15+
* @param string $data may contain binary data
16+
*/
1217
final public function __construct(
1318
public readonly string $data = '',
1419
) {
@@ -20,7 +25,9 @@ final public function withData(string $data): static
2025
}
2126

2227
/**
23-
* @deprecated use readonly property $data
28+
* @deprecated use readonly property {@see self::$data}
29+
*
30+
* @return string may contain binary data
2431
*/
2532
final public function getData(): string
2633
{
@@ -61,4 +68,14 @@ abstract public function xz(): static;
6168
* @throws Coder\Exception\CoderException
6269
*/
6370
abstract public function zlib(): static;
71+
72+
/**
73+
* @note this is just a helper, this class is not supposed to implement {@see BinariableInterface}
74+
*
75+
* @return string may contain binary data
76+
*/
77+
public function __toString(): string
78+
{
79+
return $this->data;
80+
}
6481
}

0 commit comments

Comments
 (0)