From 51b960739a66135209703c1ff7b27abd897c1ad2 Mon Sep 17 00:00:00 2001 From: Petr Knap <8299754+petrknap@users.noreply.github.com> Date: Mon, 7 Apr 2025 22:12:55 +0200 Subject: [PATCH] feat: `Coder` implements `Stringable` --- src/Coder.php | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/Coder.php b/src/Coder.php index 0e21b97..a161570 100644 --- a/src/Coder.php +++ b/src/Coder.php @@ -4,11 +4,16 @@ namespace PetrKnap\Binary; +use Stringable; + /** * @internal shared logic */ -abstract class Coder +abstract class Coder implements Stringable { + /** + * @param string $data may contain binary data + */ final public function __construct( public readonly string $data = '', ) { @@ -20,7 +25,7 @@ final public function withData(string $data): static } /** - * @deprecated use readonly property $data + * @deprecated use readonly property {@see self::$data} */ final public function getData(): string { @@ -61,4 +66,12 @@ abstract public function xz(): static; * @throws Coder\Exception\CoderException */ abstract public function zlib(): static; + + /** + * @note this is just a helper, this class is not supposed to implement {@see BinariableInterface} + */ + public function __toString(): string + { + return $this->data; + } }