Skip to content

Commit

Permalink
Stan fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
Spomky committed Sep 29, 2021
1 parent 3598c8c commit 6376f58
Show file tree
Hide file tree
Showing 11 changed files with 57 additions and 19 deletions.
11 changes: 4 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
.PHONY: it
it: coding-standards tests static-analyse performance-tests mutation-tests

.PHONY: code-coverage
code-coverage: vendor ## Show test coverage rates (console)
vendor/bin/phpunit --coverage-text

.PHONY: code-coverage-html
code-coverage-html: vendor ## Show test coverage rates (HTML)
.PHONY: coverage
coverage: vendor ## Show test coverage rates (HTML)
vendor/bin/phpunit --coverage-html ./build

.PHONY: fix-coding-standards
fix-coding-standards: vendor ## Fix all files using defined PHP-CS-FIXER rules
.PHONY: fix-cs
fix-cs: vendor ## Fix all files using defined PHP-CS-FIXER rules
vendor/bin/php-cs-fixer fix

.PHONY: coding-standards
Expand Down
3 changes: 3 additions & 0 deletions src/ListObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ public function get(int $index): CBORObject
return $this->data[$index];
}

/**
* @return array<int, mixed>
*/
public function normalize(): array
{
return array_map(static function (CBORObject $object) {
Expand Down
3 changes: 3 additions & 0 deletions src/MapObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ public function getIterator(): Iterator
return new ArrayIterator($this->data);
}

/**
* @return array<mixed, mixed>
*/
public function normalize(): array
{
$result = [];
Expand Down
8 changes: 6 additions & 2 deletions src/Tag/BigFloatTag.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,12 @@ public static function createFromExponentAndMantissa(CBORObject $e, CBORObject $

public function normalize()
{
$e = $this->object->get(0);
$m = $this->object->get(1);
/** @var ListObject $object */
$object = $this->object;
/** @var UnsignedIntegerObject|NegativeIntegerObject $e */
$e = $object->get(0);
/** @var UnsignedIntegerObject|NegativeIntegerObject|NegativeBigIntegerTag|UnsignedBigIntegerTag $m */
$m = $object->get(1);

return rtrim(
bcmul(
Expand Down
11 changes: 9 additions & 2 deletions src/Tag/DatetimeTag.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,19 @@ public static function create(CBORObject $object): Tag

public function normalize(): DateTimeInterface
{
$result = DateTimeImmutable::createFromFormat(DATE_RFC3339, $this->object->normalize());
/** @var TextStringObject|IndefiniteLengthTextStringObject $object */
$object = $this->object;
$result = DateTimeImmutable::createFromFormat(DATE_RFC3339, $object->normalize());
if (false !== $result) {
return $result;
}

return DateTimeImmutable::createFromFormat('Y-m-d\TH:i:s.uP', $this->object->normalize());
$formatted = DateTimeImmutable::createFromFormat('Y-m-d\TH:i:s.uP', $object->normalize());
if (false === $formatted) {
throw new InvalidArgumentException('Invalid data. Cannot be converted into a datetime object');
}

return $formatted;
}

/**
Expand Down
8 changes: 6 additions & 2 deletions src/Tag/DecimalFractionTag.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,12 @@ public static function createFromExponentAndMantissa(CBORObject $e, CBORObject $

public function normalize()
{
$e = $this->object->get(0);
$m = $this->object->get(1);
/** @var ListObject $object */
$object = $this->object;
/** @var UnsignedIntegerObject|NegativeIntegerObject $e */
$e = $object->get(0);
/** @var UnsignedIntegerObject|NegativeIntegerObject|NegativeBigIntegerTag|UnsignedBigIntegerTag $m */
$m = $object->get(1);

return rtrim(
bcmul(
Expand Down
5 changes: 4 additions & 1 deletion src/Tag/MimeTag.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,10 @@ public static function create(CBORObject $object): Tag

public function normalize(): string
{
return $this->object->normalize();
/** @var TextStringObject|IndefiniteLengthTextStringObject $object */
$object = $this->object;

return $object->normalize();
}

/**
Expand Down
4 changes: 3 additions & 1 deletion src/Tag/NegativeBigIntegerTag.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ public static function create(CBORObject $object): Tag

public function normalize(): string
{
$integer = BigInteger::fromBase(bin2hex($this->object->getValue()), 16);
/** @var ByteStringObject|IndefiniteLengthByteStringObject $object */
$object = $this->object;
$integer = BigInteger::fromBase(bin2hex($object->getValue()), 16);
$minusOne = BigInteger::of(-1);

return $minusOne->minus($integer)->toBase(10);
Expand Down
13 changes: 11 additions & 2 deletions src/Tag/TimestampTag.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@ public function normalize(): DateTimeInterface
switch (true) {
case $object instanceof UnsignedIntegerObject:
case $object instanceof NegativeIntegerObject:
return DateTimeImmutable::createFromFormat('U', (string) $object->normalize());
$formatted = DateTimeImmutable::createFromFormat('U', (string) $object->normalize());

break;
case $object instanceof HalfPrecisionFloatObject:
case $object instanceof SinglePrecisionFloatObject:
case $object instanceof DoublePrecisionFloatObject:
Expand All @@ -72,11 +74,18 @@ public function normalize(): DateTimeInterface
$parts[1] = str_pad($parts[1], 6, '0', STR_PAD_RIGHT);
}
}
$formatted = DateTimeImmutable::createFromFormat('U.u', implode('.', $parts));

return DateTimeImmutable::createFromFormat('U.u', implode('.', $parts));
break;
default:
throw new InvalidArgumentException('Unable to normalize the object');
}

if (false === $formatted) {
throw new InvalidArgumentException('Invalid data. Cannot be converted into a datetime object');
}

return $formatted;
}

/**
Expand Down
5 changes: 4 additions & 1 deletion src/Tag/UnsignedBigIntegerTag.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,10 @@ public static function create(CBORObject $object): Tag

public function normalize(): string
{
return Utils::hexToString($this->object->normalize());
/** @var ByteStringObject|IndefiniteLengthByteStringObject $object */
$object = $this->object;

return Utils::hexToString($object->normalize());
}

/**
Expand Down
5 changes: 4 additions & 1 deletion src/Tag/UriTag.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,10 @@ public static function create(CBORObject $object): Tag

public function normalize(): string
{
return $this->object->normalize();
/** @var TextStringObject|IndefiniteLengthTextStringObject $object */
$object = $this->object;

return $object->normalize();
}

/**
Expand Down

0 comments on commit 6376f58

Please sign in to comment.