Skip to content

Commit

Permalink
Remove Serializable
Browse files Browse the repository at this point in the history
  • Loading branch information
BenMorel committed Aug 9, 2023
1 parent 12eaa7c commit 4ecc3c9
Show file tree
Hide file tree
Showing 8 changed files with 5 additions and 91 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ All notable changes to this project will be documented in this file.

- Minimum PHP version is now 8.1
- `RoundingMode` is now an `enum`; if you're type-hinting rounding modes, you need to type-hint against `RoundingMode` instead of `int` now
- `BigNumber` classes do not implement the `Serializable` interface anymore (they use the [new custom object serialization mechanism](https://wiki.php.net/rfc/custom_object_serialization))

## [0.11.0](https://github.com/brick/math/releases/tag/0.11.0) - 2023-01-16

Expand Down
30 changes: 0 additions & 30 deletions src/BigDecimal.php
Original file line number Diff line number Diff line change
Expand Up @@ -693,36 +693,6 @@ public function __unserialize(array $data): void
$this->scale = $data['scale'];
}

/**
* This method is required by interface Serializable and SHOULD NOT be accessed directly.
*
* @internal
*/
public function serialize() : string
{
return $this->value . ':' . $this->scale;
}

/**
* This method is only here to implement interface Serializable and cannot be accessed directly.
*
* @internal
* @psalm-suppress RedundantPropertyInitializationCheck
*
* @throws \LogicException
*/
public function unserialize($value) : void
{
if (isset($this->value)) {
throw new \LogicException('unserialize() is an internal function, it must not be called directly.');
}

[$value, $scale] = \explode(':', $value);

$this->value = $value;
$this->scale = (int) $scale;
}

/**
* Puts the internal values of the given decimal numbers on the same scale.
*
Expand Down
27 changes: 0 additions & 27 deletions src/BigInteger.php
Original file line number Diff line number Diff line change
Expand Up @@ -1050,31 +1050,4 @@ public function __unserialize(array $data): void

$this->value = $data['value'];
}

/**
* This method is required by interface Serializable and SHOULD NOT be accessed directly.
*
* @internal
*/
public function serialize() : string
{
return $this->value;
}

/**
* This method is only here to implement interface Serializable and cannot be accessed directly.
*
* @internal
* @psalm-suppress RedundantPropertyInitializationCheck
*
* @throws \LogicException
*/
public function unserialize($value) : void
{
if (isset($this->value)) {
throw new \LogicException('unserialize() is an internal function, it must not be called directly.');
}

$this->value = $value;
}
}
2 changes: 1 addition & 1 deletion src/BigNumber.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
*
* @psalm-immutable
*/
abstract class BigNumber implements \Serializable, \JsonSerializable
abstract class BigNumber implements \JsonSerializable
{
/**
* The regular expression used to parse integer, decimal and rational numbers.
Expand Down
30 changes: 0 additions & 30 deletions src/BigRational.php
Original file line number Diff line number Diff line change
Expand Up @@ -412,34 +412,4 @@ public function __unserialize(array $data): void
$this->numerator = $data['numerator'];
$this->denominator = $data['denominator'];
}

/**
* This method is required by interface Serializable and SHOULD NOT be accessed directly.
*
* @internal
*/
public function serialize() : string
{
return $this->numerator . '/' . $this->denominator;
}

/**
* This method is only here to implement interface Serializable and cannot be accessed directly.
*
* @internal
* @psalm-suppress RedundantPropertyInitializationCheck
*
* @throws \LogicException
*/
public function unserialize($value) : void
{
if (isset($this->numerator)) {
throw new \LogicException('unserialize() is an internal function, it must not be called directly.');
}

[$numerator, $denominator] = \explode('/', $value);

$this->numerator = BigInteger::of($numerator);
$this->denominator = BigInteger::of($denominator);
}
}
2 changes: 1 addition & 1 deletion tests/BigDecimalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2585,6 +2585,6 @@ public function testSerialize() : void
public function testDirectCallToUnserialize() : void
{
$this->expectException(\LogicException::class);
BigDecimal::zero()->unserialize('123:0');
BigDecimal::zero()->__unserialize([]);
}
}
2 changes: 1 addition & 1 deletion tests/BigIntegerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3762,7 +3762,7 @@ public function testSerialize() : void
public function testDirectCallToUnserialize() : void
{
$this->expectException(\LogicException::class);
BigInteger::zero()->unserialize('123');
BigInteger::zero()->__unserialize([]);
}

public function testJsonSerialize() : void
Expand Down
2 changes: 1 addition & 1 deletion tests/BigRationalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -983,6 +983,6 @@ public function testSerialize() : void
public function testDirectCallToUnserialize() : void
{
$this->expectException(\LogicException::class);
BigRational::nd(1, 2)->unserialize('123/456');
BigRational::nd(1, 2)->__unserialize([]);
}
}

0 comments on commit 4ecc3c9

Please sign in to comment.