Skip to content

Commit

Permalink
Introduction to Tag and OtherObject interfaces
Browse files Browse the repository at this point in the history
  • Loading branch information
Spomky committed Jun 26, 2022
1 parent de06c1b commit 869006a
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 40 deletions.
16 changes: 0 additions & 16 deletions .github/ISSUE_TEMPLATE.md

This file was deleted.

11 changes: 3 additions & 8 deletions src/OtherObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
}
17 changes: 17 additions & 0 deletions src/OtherObject/OtherObjectInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

declare(strict_types=1);

namespace CBOR\OtherObject;

use CBOR\CBORObject;

interface OtherObjectInterface extends CBORObject
{
/**
* @return int[]
*/
public static function supportedAdditionalInformation(): array;

public static function createFromLoadedData(int $additionalInformation, ?string $data): self;
}
2 changes: 1 addition & 1 deletion src/OtherObject/OtherObjectManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function getClassForValue(int $value): string
return array_key_exists($value, $this->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);
Expand Down
4 changes: 1 addition & 3 deletions src/OtherObject/OtherObjectManagerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
11 changes: 2 additions & 9 deletions src/Tag.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
Expand Down
20 changes: 20 additions & 0 deletions src/Tag/TagInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

declare(strict_types=1);

namespace CBOR\Tag;

use CBOR\CBORObject;

interface TagInterface extends CBORObject
{
public static function getTagId(): int;

public function getValue(): CBORObject;

public static function createFromLoadedData(
int $additionalInformation,
?string $data,
CBORObject $object
): self;
}
2 changes: 1 addition & 1 deletion src/Tag/TagManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function getClassForValue(int $value): string
return array_key_exists($value, $this->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) {
Expand Down
3 changes: 1 addition & 2 deletions src/Tag/TagManagerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

0 comments on commit 869006a

Please sign in to comment.