From 869006a8178fd7d3ba7b6dde4a9e203e7b97b105 Mon Sep 17 00:00:00 2001 From: Florent Morselli Date: Sun, 26 Jun 2022 10:19:34 +0200 Subject: [PATCH] Introduction to Tag and OtherObject interfaces --- .github/ISSUE_TEMPLATE.md | 16 --------------- src/OtherObject.php | 11 +++------- src/OtherObject/OtherObjectInterface.php | 17 ++++++++++++++++ src/OtherObject/OtherObjectManager.php | 2 +- .../OtherObjectManagerInterface.php | 4 +--- src/Tag.php | 11 ++-------- src/Tag/TagInterface.php | 20 +++++++++++++++++++ src/Tag/TagManager.php | 2 +- src/Tag/TagManagerInterface.php | 3 +-- 9 files changed, 46 insertions(+), 40 deletions(-) delete mode 100644 .github/ISSUE_TEMPLATE.md create mode 100644 src/OtherObject/OtherObjectInterface.php create mode 100644 src/Tag/TagInterface.php diff --git a/.github/ISSUE_TEMPLATE.md b/.github/ISSUE_TEMPLATE.md deleted file mode 100644 index 2ceb8da..0000000 --- a/.github/ISSUE_TEMPLATE.md +++ /dev/null @@ -1,16 +0,0 @@ -| Q | A -| -------------------- | ----- -| Bug report? | yes/no -| Feature request? | yes/no -| BC Break report? | yes/no -| RFC? / Specification | yes/no -| Library version | x.y(.z) - - diff --git a/src/OtherObject.php b/src/OtherObject.php index 150638b..5bddabc 100644 --- a/src/OtherObject.php +++ b/src/OtherObject.php @@ -4,7 +4,9 @@ namespace CBOR; -abstract class OtherObject extends AbstractCBORObject +use CBOR\OtherObject\OtherObjectInterface; + +abstract class OtherObject extends AbstractCBORObject implements OtherObjectInterface { private const MAJOR_TYPE = self::MAJOR_TYPE_OTHER_TYPE; @@ -29,11 +31,4 @@ public function getContent(): ?string { return $this->data; } - - /** - * @return int[] - */ - abstract public static function supportedAdditionalInformation(): array; - - abstract public static function createFromLoadedData(int $additionalInformation, ?string $data): self; } diff --git a/src/OtherObject/OtherObjectInterface.php b/src/OtherObject/OtherObjectInterface.php new file mode 100644 index 0000000..08b69e9 --- /dev/null +++ b/src/OtherObject/OtherObjectInterface.php @@ -0,0 +1,17 @@ +classes) ? $this->classes[$value] : GenericObject::class; } - public function createObjectForValue(int $value, ?string $data): OtherObject + public function createObjectForValue(int $value, ?string $data): OtherObjectInterface { /** @var OtherObject $class */ $class = $this->getClassForValue($value); diff --git a/src/OtherObject/OtherObjectManagerInterface.php b/src/OtherObject/OtherObjectManagerInterface.php index b0b2f14..9d6d7ea 100644 --- a/src/OtherObject/OtherObjectManagerInterface.php +++ b/src/OtherObject/OtherObjectManagerInterface.php @@ -4,9 +4,7 @@ namespace CBOR\OtherObject; -use CBOR\OtherObject; - interface OtherObjectManagerInterface { - public function createObjectForValue(int $value, ?string $data): OtherObject; + public function createObjectForValue(int $value, ?string $data): OtherObjectInterface; } diff --git a/src/Tag.php b/src/Tag.php index c95babd..556c85d 100644 --- a/src/Tag.php +++ b/src/Tag.php @@ -4,9 +4,10 @@ namespace CBOR; +use CBOR\Tag\TagInterface; use InvalidArgumentException; -abstract class Tag extends AbstractCBORObject +abstract class Tag extends AbstractCBORObject implements TagInterface { private const MAJOR_TYPE = self::MAJOR_TYPE_TAG; @@ -33,14 +34,6 @@ public function getData(): ?string return $this->data; } - abstract public static function getTagId(): int; - - abstract public static function createFromLoadedData( - int $additionalInformation, - ?string $data, - CBORObject $object - ): self; - public function getValue(): CBORObject { return $this->object; diff --git a/src/Tag/TagInterface.php b/src/Tag/TagInterface.php new file mode 100644 index 0000000..fbd24a7 --- /dev/null +++ b/src/Tag/TagInterface.php @@ -0,0 +1,20 @@ +classes) ? $this->classes[$value] : GenericTag::class; } - public function createObjectForValue(int $additionalInformation, ?string $data, CBORObject $object): Tag + public function createObjectForValue(int $additionalInformation, ?string $data, CBORObject $object): TagInterface { $value = $additionalInformation; if ($additionalInformation >= 24) { diff --git a/src/Tag/TagManagerInterface.php b/src/Tag/TagManagerInterface.php index eead85e..2e21d34 100644 --- a/src/Tag/TagManagerInterface.php +++ b/src/Tag/TagManagerInterface.php @@ -5,9 +5,8 @@ namespace CBOR\Tag; use CBOR\CBORObject; -use CBOR\Tag; interface TagManagerInterface { - public function createObjectForValue(int $additionalInformation, ?string $data, CBORObject $object): Tag; + public function createObjectForValue(int $additionalInformation, ?string $data, CBORObject $object): TagInterface; }