Skip to content

Commit

Permalink
Preparation v3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Spomky committed Nov 17, 2021
1 parent 68e25bc commit abdde5e
Show file tree
Hide file tree
Showing 69 changed files with 93 additions and 800 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
}
},
"require": {
"php": ">=7.3",
"brick/math": "^0.8.15|^0.9.0",
"php": ">=8.0",
"brick/math": "^0.9.0",
"ext-mbstring": "*"
},
"require-dev": {
Expand Down
32 changes: 0 additions & 32 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -28,35 +28,3 @@ parameters:
message: '#Instanceof between CBOR\\MapItem and CBOR\\MapItem will always evaluate to true\.#'
count: 1
path: src/MapObject.php
-
message: '#Class CBOR\\TextStringWithChunkObject extends \@final class CBOR\\IndefiniteLengthTextStringObject\.#'
count: 1
path: src/TextStringWithChunkObject.php
-
message: '#Class CBOR\\Tag\\TagObjectManager extends \@final class CBOR\\Tag\\TagManager\.#'
count: 1
path: src/Tag/TagObjectManager.php
-
message: '#Class CBOR\\Tag\\PositiveBigIntegerTag extends \@final class CBOR\\Tag\\UnsignedBigIntegerTag\.#'
count: 1
path: src/Tag/PositiveBigIntegerTag.php
-
message: '#Class CBOR\\Tag\\EpochTag extends \@final class CBOR\\Tag\\DatetimeTag\.#'
count: 1
path: src/Tag/EpochTag.php
-
message: '#Class CBOR\\SignedIntegerObject extends \@final class CBOR\\NegativeIntegerObject\.#'
count: 1
path: src/SignedIntegerObject.php
-
message: '#Class CBOR\\InfiniteMapObject extends \@final class CBOR\\IndefiniteLengthMapObject\.#'
count: 1
path: src/InfiniteMapObject.php
-
message: '#Class CBOR\\InfiniteListObject extends \@final class CBOR\\IndefiniteLengthListObject\.#'
count: 1
path: src/InfiniteListObject.php
-
message: '#Class CBOR\\ByteStringWithChunkObject extends \@final class CBOR\\IndefiniteLengthByteStringObject\.#'
count: 1
path: src/ByteStringWithChunkObject.php
4 changes: 2 additions & 2 deletions rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@

return static function (ContainerConfigurator $containerConfigurator): void {
$containerConfigurator->import(SetList::DEAD_CODE);
$containerConfigurator->import(SetList::PHP_73);
$containerConfigurator->import(SetList::PHP_80);
$containerConfigurator->import(SymfonySetList::SYMFONY_52_VALIDATOR_ATTRIBUTES);
$containerConfigurator->import(SymfonySetList::SYMFONY_CODE_QUALITY);
$containerConfigurator->import(SymfonySetList::SYMFONY_CONSTRUCTOR_INJECTION);
$containerConfigurator->import(SymfonySetList::SYMFONY_CODE_QUALITY);
$parameters = $containerConfigurator->parameters();
$parameters->set(Option::PATHS, [__DIR__ . '/src', __DIR__ . '/tests']);
$parameters->set(Option::PHP_VERSION_FEATURES, PhpVersion::PHP_73);
$parameters->set(Option::PHP_VERSION_FEATURES, PhpVersion::PHP_80);
$parameters->set(Option::AUTO_IMPORT_NAMES, true);
$parameters->set(Option::IMPORT_SHORT_CLASSES, false);
$parameters->set(Option::IMPORT_DOC_BLOCKS, false);
Expand Down
21 changes: 6 additions & 15 deletions src/AbstractCBORObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,14 @@
namespace CBOR;

use function chr;
use Stringable;

abstract class AbstractCBORObject implements CBORObject
abstract class AbstractCBORObject implements CBORObject, Stringable
{
/**
* @var int
*/
protected $additionalInformation;

/**
* @var int
*/
private $majorType;

public function __construct(int $majorType, int $additionalInformation)
{
$this->majorType = $majorType;
$this->additionalInformation = $additionalInformation;
public function __construct(
private int $majorType,
protected int $additionalInformation
) {
}

public function __toString(): string
Expand Down
18 changes: 2 additions & 16 deletions src/ByteStringObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,9 @@ final class ByteStringObject extends AbstractCBORObject implements Normalizable
{
private const MAJOR_TYPE = self::MAJOR_TYPE_BYTE_STRING;

/**
* @var string
*/
private $value;
private string $value;

/**
* @var string|null
*/
private $length;
private ?string $length = null;

public function __construct(string $data)
{
Expand Down Expand Up @@ -56,12 +50,4 @@ public function normalize(): string
{
return $this->value;
}

/**
* @deprecated The method will be removed on v3.0. Please use CBOR\Normalizable interface
*/
public function getNormalizedData(bool $ignoreTags = false): string
{
return $this->normalize();
}
}
12 changes: 0 additions & 12 deletions src/ByteStringWithChunkObject.php

This file was deleted.

7 changes: 0 additions & 7 deletions src/CBORObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,4 @@ public function __toString(): string;
public function getMajorType(): int;

public function getAdditionalInformation(): int;

/**
* @deprecated The method will be removed on v3.0. Please use CBOR\Normalizable interface
*
* @return mixed|null
*/
public function getNormalizedData(bool $ignoreTags = false);
}
12 changes: 3 additions & 9 deletions src/Decoder.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,9 @@

final class Decoder implements DecoderInterface
{
/**
* @var Tag\TagManagerInterface
*/
private $tagObjectManager;

/**
* @var OtherObject\OtherObjectManagerInterface
*/
private $otherTypeManager;
private TagManagerInterface $tagObjectManager;

private OtherObjectManagerInterface $otherTypeManager;

public function __construct(
?TagManagerInterface $tagObjectManager = null,
Expand Down
15 changes: 2 additions & 13 deletions src/IndefiniteLengthByteStringObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@

namespace CBOR;

/**
* @final
*/
class IndefiniteLengthByteStringObject extends AbstractCBORObject implements Normalizable
final class IndefiniteLengthByteStringObject extends AbstractCBORObject implements Normalizable
{
private const MAJOR_TYPE = self::MAJOR_TYPE_BYTE_STRING;

Expand All @@ -16,7 +13,7 @@ class IndefiniteLengthByteStringObject extends AbstractCBORObject implements Nor
/**
* @var ByteStringObject[]
*/
private $chunks = [];
private array $chunks = [];

public function __construct()
{
Expand Down Expand Up @@ -81,12 +78,4 @@ public function normalize(): string

return $result;
}

/**
* @deprecated The method will be removed on v3.0. Please use CBOR\Normalizable interface
*/
public function getNormalizedData(bool $ignoreTags = false): string
{
return $this->normalize();
}
}
24 changes: 2 additions & 22 deletions src/IndefiniteLengthListObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
use function array_key_exists;
use ArrayAccess;
use ArrayIterator;
use function count;
use Countable;
use InvalidArgumentException;
use Iterator;
use IteratorAggregate;
Expand All @@ -18,7 +16,7 @@
* @phpstan-implements IteratorAggregate<int, CBORObject>
* @final
*/
class IndefiniteLengthListObject extends AbstractCBORObject implements Countable, IteratorAggregate, Normalizable, ArrayAccess
class IndefiniteLengthListObject extends AbstractCBORObject implements IteratorAggregate, Normalizable, ArrayAccess
{
private const MAJOR_TYPE = self::MAJOR_TYPE_LIST;

Expand All @@ -27,7 +25,7 @@ class IndefiniteLengthListObject extends AbstractCBORObject implements Countable
/**
* @var CBORObject[]
*/
private $data = [];
private array $data = [];

public function __construct()
{
Expand Down Expand Up @@ -59,16 +57,6 @@ public function normalize(): array
}, $this->data);
}

/**
* @deprecated The method will be removed on v3.0. Please use CBOR\Normalizable interface
*
* @return mixed[]
*/
public function getNormalizedData(bool $ignoreTags = false): array
{
return $this->normalize();
}

public function add(CBORObject $item): self
{
$this->data[] = $item;
Expand Down Expand Up @@ -112,14 +100,6 @@ public function set(int $index, CBORObject $object): self
return $this;
}

/**
* @deprecated The method will be removed on v3.0. No replacement
*/
public function count(): int
{
return count($this->data);
}

/**
* @return Iterator<int, CBORObject>
*/
Expand Down
47 changes: 5 additions & 42 deletions src/IndefiniteLengthMapObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
use function array_key_exists;
use ArrayAccess;
use ArrayIterator;
use function count;
use Countable;
use InvalidArgumentException;
use Iterator;
use IteratorAggregate;
Expand All @@ -18,7 +16,7 @@
* @phpstan-implements IteratorAggregate<int, MapItem>
* @final
*/
class IndefiniteLengthMapObject extends AbstractCBORObject implements Countable, IteratorAggregate, Normalizable, ArrayAccess
class IndefiniteLengthMapObject extends AbstractCBORObject implements IteratorAggregate, Normalizable, ArrayAccess
{
private const MAJOR_TYPE = self::MAJOR_TYPE_MAP;

Expand All @@ -27,7 +25,7 @@ class IndefiniteLengthMapObject extends AbstractCBORObject implements Countable,
/**
* @var MapItem[]
*/
private $data = [];
private array $data = [];

public function __construct()
{
Expand All @@ -50,14 +48,6 @@ public static function create(): self
return new self();
}

/**
* @deprecated The method will be removed on v3.0. Please use "add" instead
*/
public function append(CBORObject $key, CBORObject $value): self
{
return $this->add($key, $value);
}

public function add(CBORObject $key, CBORObject $value): self
{
if (! $key instanceof Normalizable) {
Expand All @@ -68,18 +58,12 @@ public function add(CBORObject $key, CBORObject $value): self
return $this;
}

/**
* @param int|string $key
*/
public function has($key): bool
public function has(int|string $key): bool
{
return array_key_exists($key, $this->data);
}

/**
* @param int|string $index
*/
public function remove($index): self
public function remove(int|string $index): self
{
if (! $this->has($index)) {
return $this;
Expand All @@ -90,10 +74,7 @@ public function remove($index): self
return $this;
}

/**
* @param int|string $index
*/
public function get($index): CBORObject
public function get(int|string $index): CBORObject
{
if (! $this->has($index)) {
throw new InvalidArgumentException('Index not found.');
Expand All @@ -114,14 +95,6 @@ public function set(MapItem $object): self
return $this;
}

/**
* @deprecated The method will be removed on v3.0. No replacement
*/
public function count(): int
{
return count($this->data);
}

/**
* @return Iterator<int, MapItem>
*/
Expand All @@ -147,16 +120,6 @@ public function normalize(): array
}, []);
}

/**
* @deprecated The method will be removed on v3.0. Please use CBOR\Normalizable interface
*
* @return mixed[]
*/
public function getNormalizedData(bool $ignoreTags = false): array
{
return $this->normalize();
}

public function offsetExists($offset): bool
{
return $this->has($offset);
Expand Down
Loading

0 comments on commit abdde5e

Please sign in to comment.