Skip to content

Commit

Permalink
Stan errors fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
Spomky committed Oct 21, 2021
1 parent 2bacf90 commit a1459b1
Show file tree
Hide file tree
Showing 14 changed files with 101 additions and 63 deletions.
26 changes: 26 additions & 0 deletions rector.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

declare(strict_types=1);

use Rector\Core\Configuration\Option;
use Rector\Core\ValueObject\PhpVersion;
use Rector\Php74\Rector\Property\TypedPropertyRector;
use Rector\Set\ValueObject\SetList;
use Rector\Symfony\Set\SymfonySetList;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;

return static function (ContainerConfigurator $containerConfigurator): void {
$containerConfigurator->import(SetList::DEAD_CODE);
$containerConfigurator->import(SetList::PHP_73);
$containerConfigurator->import(SymfonySetList::SYMFONY_52);
$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::AUTO_IMPORT_NAMES, true);
$parameters->set(Option::IMPORT_SHORT_CLASSES, false);
$parameters->set(Option::IMPORT_DOC_BLOCKS, false);

$services = $containerConfigurator->services();
$services->set(TypedPropertyRector::class);
};
3 changes: 1 addition & 2 deletions src/ByteStringObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,8 @@ public function __toString(): string
if (null !== $this->length) {
$result .= $this->length;
}
$result .= $this->value;

return $result;
return $result.$this->value;
}

public function getValue(): string
Expand Down
98 changes: 63 additions & 35 deletions src/Decoder.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,34 @@

namespace CBOR;

use CBOR\OtherObject\BreakObject;
use CBOR\OtherObject\DoublePrecisionFloatObject;
use CBOR\OtherObject\FalseObject;
use CBOR\OtherObject\HalfPrecisionFloatObject;
use CBOR\OtherObject\NullObject;
use CBOR\OtherObject\OtherObjectManager;
use CBOR\OtherObject\OtherObjectManagerInterface;
use CBOR\OtherObject\SimpleObject;
use CBOR\OtherObject\SinglePrecisionFloatObject;
use CBOR\OtherObject\TrueObject;
use CBOR\OtherObject\UndefinedObject;
use CBOR\Tag\Base16EncodingTag;
use CBOR\Tag\Base64EncodingTag;
use CBOR\Tag\Base64Tag;
use CBOR\Tag\Base64UrlEncodingTag;
use CBOR\Tag\Base64UrlTag;
use CBOR\Tag\BigFloatTag;
use CBOR\Tag\CBOREncodingTag;
use CBOR\Tag\CBORTag;
use CBOR\Tag\DatetimeTag;
use CBOR\Tag\DecimalFractionTag;
use CBOR\Tag\MimeTag;
use CBOR\Tag\NegativeBigIntegerTag;
use CBOR\Tag\TagManager;
use CBOR\Tag\TagManagerInterface;
use CBOR\Tag\TimestampTag;
use CBOR\Tag\UnsignedBigIntegerTag;
use CBOR\Tag\UriTag;
use InvalidArgumentException;
use function ord;
use RuntimeException;
Expand All @@ -29,13 +57,13 @@ final class Decoder implements DecoderInterface
*/
private $otherTypeManager;

public function __construct(?Tag\TagManagerInterface $tagObjectManager = null, ?OtherObject\OtherObjectManagerInterface $otherTypeManager = null)
public function __construct(?TagManagerInterface $tagObjectManager = null, ?OtherObjectManagerInterface $otherTypeManager = null)
{
$this->tagObjectManager = $tagObjectManager ?? $this->generateTagManager();
$this->otherTypeManager = $otherTypeManager ?? $this->generateOtherObjectManager();
}

public static function create(?Tag\TagManagerInterface $tagObjectManager = null, ?OtherObject\OtherObjectManagerInterface $otherTypeManager = null): self
public static function create(?TagManagerInterface $tagObjectManager = null, ?OtherObjectManagerInterface $otherTypeManager = null): self
{
return new self($tagObjectManager, $otherTypeManager);
}
Expand Down Expand Up @@ -114,7 +142,7 @@ private function processInfinite(Stream $stream, int $mt, bool $breakable): CBOR
switch ($mt) {
case CBORObject::MAJOR_TYPE_BYTE_STRING: //2
$object = IndefiniteLengthByteStringObject::create();
while (!($it = $this->process($stream, true)) instanceof OtherObject\BreakObject) {
while (!($it = $this->process($stream, true)) instanceof BreakObject) {
if (!$it instanceof ByteStringObject) {
throw new RuntimeException('Unable to parse the data. Infinite Byte String object can only get Byte String objects.');
}
Expand All @@ -124,7 +152,7 @@ private function processInfinite(Stream $stream, int $mt, bool $breakable): CBOR
return $object;
case CBORObject::MAJOR_TYPE_TEXT_STRING: //3
$object = IndefiniteLengthTextStringObject::create();
while (!($it = $this->process($stream, true)) instanceof OtherObject\BreakObject) {
while (!($it = $this->process($stream, true)) instanceof BreakObject) {
if (!$it instanceof TextStringObject) {
throw new RuntimeException('Unable to parse the data. Infinite Text String object can only get Text String objects.');
}
Expand All @@ -134,14 +162,14 @@ private function processInfinite(Stream $stream, int $mt, bool $breakable): CBOR
return $object;
case CBORObject::MAJOR_TYPE_LIST: //4
$object = IndefiniteLengthListObject::create();
while (!($it = $this->process($stream, true)) instanceof OtherObject\BreakObject) {
while (!($it = $this->process($stream, true)) instanceof BreakObject) {
$object->add($it);
}

return $object;
case CBORObject::MAJOR_TYPE_MAP: //5
$object = IndefiniteLengthMapObject::create();
while (!($it = $this->process($stream, true)) instanceof OtherObject\BreakObject) {
while (!($it = $this->process($stream, true)) instanceof BreakObject) {
$object->add($it, $this->process($stream, false));
}

Expand All @@ -151,7 +179,7 @@ private function processInfinite(Stream $stream, int $mt, bool $breakable): CBOR
throw new InvalidArgumentException('Cannot parse the data. No enclosing indefinite.');
}

return OtherObject\BreakObject::create();
return BreakObject::create();
case CBORObject::MAJOR_TYPE_UNSIGNED_INTEGER: //0
case CBORObject::MAJOR_TYPE_NEGATIVE_INTEGER: //1
case CBORObject::MAJOR_TYPE_TAG: //6
Expand All @@ -160,44 +188,44 @@ private function processInfinite(Stream $stream, int $mt, bool $breakable): CBOR
}
}

private function generateTagManager(): Tag\TagManagerInterface
private function generateTagManager(): TagManagerInterface
{
return Tag\TagManager::create()
->add(Tag\DatetimeTag::class)
->add(Tag\TimestampTag::class)
return TagManager::create()
->add(DatetimeTag::class)
->add(TimestampTag::class)

->add(Tag\UnsignedBigIntegerTag::class)
->add(Tag\NegativeBigIntegerTag::class)
->add(UnsignedBigIntegerTag::class)
->add(NegativeBigIntegerTag::class)

->add(Tag\DecimalFractionTag::class)
->add(Tag\BigFloatTag::class)
->add(DecimalFractionTag::class)
->add(BigFloatTag::class)

->add(Tag\Base64UrlEncodingTag::class)
->add(Tag\Base64EncodingTag::class)
->add(Tag\Base16EncodingTag::class)
->add(Tag\CBOREncodingTag::class)
->add(Base64UrlEncodingTag::class)
->add(Base64EncodingTag::class)
->add(Base16EncodingTag::class)
->add(CBOREncodingTag::class)

->add(Tag\UriTag::class)
->add(Tag\Base64UrlTag::class)
->add(Tag\Base64Tag::class)
->add(Tag\MimeTag::class)
->add(UriTag::class)
->add(Base64UrlTag::class)
->add(Base64Tag::class)
->add(MimeTag::class)

->add(Tag\CBORTag::class)
->add(CBORTag::class)
;
}

private function generateOtherObjectManager(): OtherObject\OtherObjectManagerInterface
private function generateOtherObjectManager(): OtherObjectManagerInterface
{
return OtherObject\OtherObjectManager::create()
->add(OtherObject\BreakObject::class)
->add(OtherObject\SimpleObject::class)
->add(OtherObject\FalseObject::class)
->add(OtherObject\TrueObject::class)
->add(OtherObject\NullObject::class)
->add(OtherObject\UndefinedObject::class)
->add(OtherObject\HalfPrecisionFloatObject::class)
->add(OtherObject\SinglePrecisionFloatObject::class)
->add(OtherObject\DoublePrecisionFloatObject::class)
return OtherObjectManager::create()
->add(BreakObject::class)
->add(SimpleObject::class)
->add(FalseObject::class)
->add(TrueObject::class)
->add(NullObject::class)
->add(UndefinedObject::class)
->add(HalfPrecisionFloatObject::class)
->add(SinglePrecisionFloatObject::class)
->add(DoublePrecisionFloatObject::class)
;
}
}
3 changes: 1 addition & 2 deletions src/IndefiniteLengthByteStringObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,8 @@ public function __toString(): string
foreach ($this->chunks as $chunk) {
$result .= $chunk->__toString();
}
$result .= "\xFF";

return $result;
return $result."\xFF";
}

public function add(ByteStringObject $chunk): self
Expand Down
3 changes: 1 addition & 2 deletions src/IndefiniteLengthListObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,8 @@ public function __toString(): string
foreach ($this->data as $object) {
$result .= (string) $object;
}
$result .= "\xFF";

return $result;
return $result."\xFF";
}

/**
Expand Down
3 changes: 1 addition & 2 deletions src/IndefiniteLengthMapObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,8 @@ public function __toString(): string
$result .= (string) $object->getKey();
$result .= (string) $object->getValue();
}
$result .= "\xFF";

return $result;
return $result."\xFF";
}

/**
Expand Down
3 changes: 1 addition & 2 deletions src/IndefiniteLengthTextStringObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,8 @@ public function __toString(): string
foreach ($this->data as $object) {
$result .= (string) $object;
}
$result .= "\xFF";

return $result;
return $result."\xFF";
}

public function add(TextStringObject $chunk): self
Expand Down
8 changes: 4 additions & 4 deletions src/LengthCalculator.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,11 @@ private static function computeLength(int $length): array
case $length <= 0xFF:
return [24, chr($length)];
case $length <= 0xFFFF:
return [25, self::hex2bin(static::fixHexLength(Utils::intToHex($length)))];
return [25, self::hex2bin(dechex($length))];
case $length <= 0xFFFFFFFF:
return [26, self::hex2bin(static::fixHexLength(Utils::intToHex($length)))];
case BigInteger::of($length)->isLessThanOrEqualTo(BigInteger::fromBase('FFFFFFFFFFFFFFFF', 16)):
return [27, self::hex2bin(static::fixHexLength(Utils::intToHex($length)))];
return [26, self::hex2bin(dechex($length))];
case BigInteger::of($length)->isLessThan(BigInteger::fromBase('FFFFFFFFFFFFFFFF', 16)):
return [27, self::hex2bin(dechex($length))];
default:
return [31, null];
}
Expand Down
3 changes: 0 additions & 3 deletions src/OtherObject/HalfPrecisionFloatObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,6 @@ public static function createFromLoadedData(int $additionalInformation, ?string
return new self($additionalInformation, $data);
}

/**
* @return HalfPrecisionFloatObject
*/
public static function create(string $value): self
{
if (2 !== mb_strlen($value, '8bit')) {
Expand Down
3 changes: 0 additions & 3 deletions src/OtherObject/SimpleObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,6 @@ public function getNormalizedData(bool $ignoreTags = false): int
return $this->normalize();
}

/**
* @return SimpleObject
*/
public static function create(int $value): self
{
switch (true) {
Expand Down
3 changes: 0 additions & 3 deletions src/OtherObject/SinglePrecisionFloatObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,6 @@ public static function createFromLoadedData(int $additionalInformation, ?string
return new self($additionalInformation, $data);
}

/**
* @return SinglePrecisionFloatObject
*/
public static function create(string $value): self
{
if (4 !== mb_strlen($value, '8bit')) {
Expand Down
3 changes: 1 addition & 2 deletions src/Tag.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,8 @@ public function __toString(): string
if (null !== $this->data) {
$result .= $this->data;
}
$result .= (string) $this->object;

return $result;
return $result.$this->object;
}

public function getData(): ?string
Expand Down
2 changes: 1 addition & 1 deletion src/Tag/TimestampTag.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public function normalize(): DateTimeInterface
switch (true) {
case $object instanceof UnsignedIntegerObject:
case $object instanceof NegativeIntegerObject:
$formatted = DateTimeImmutable::createFromFormat('U', (string) $object->normalize());
$formatted = DateTimeImmutable::createFromFormat('U', $object->normalize());

break;
case $object instanceof HalfPrecisionFloatObject:
Expand Down
3 changes: 1 addition & 2 deletions src/TextStringObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,8 @@ public function __toString(): string
if (null !== $this->length) {
$result .= $this->length;
}
$result .= $this->data;

return $result;
return $result.$this->data;
}

public function getValue(): string
Expand Down

0 comments on commit a1459b1

Please sign in to comment.