Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add un/serialize for currency #779

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 31 additions & 1 deletion src/Currency.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Money;

use JsonSerializable;
use Serializable;

use function strtoupper;

Expand All @@ -15,7 +16,7 @@
*
* @psalm-immutable
*/
final class Currency implements JsonSerializable
final class Currency implements JsonSerializable, Serializable
{
/**
* Currency code.
Expand Down Expand Up @@ -57,4 +58,33 @@
{
return $this->code;
}

/**
* @return array<string, string>
*/
public function __serialize(): array
{
return ['code' => $this->code];
}

// TODO Correct PSALM?
public function __unserialize(array $data): void
{
$this->code = (string) $data['code'];

Check failure on line 73 in src/Currency.php

View workflow job for this annotation

GitHub Actions / Build lowest version

PropertyTypeCoercion

src/Currency.php:73:23: PropertyTypeCoercion: $this->code expects 'non-empty-string', parent type 'string' provided (see https://psalm.dev/198)

Check failure on line 73 in src/Currency.php

View workflow job for this annotation

GitHub Actions / Psalm

PropertyTypeCoercion

src/Currency.php:73:23: PropertyTypeCoercion: $this->code expects 'non-empty-string', parent type 'string' provided (see https://psalm.dev/198)

Check failure on line 73 in src/Currency.php

View workflow job for this annotation

GitHub Actions / Build (8.1)

PropertyTypeCoercion

src/Currency.php:73:23: PropertyTypeCoercion: $this->code expects 'non-empty-string', parent type 'string' provided (see https://psalm.dev/198)

Check failure on line 73 in src/Currency.php

View workflow job for this annotation

GitHub Actions / Build (8.2)

PropertyTypeCoercion

src/Currency.php:73:23: PropertyTypeCoercion: $this->code expects 'non-empty-string', parent type 'string' provided (see https://psalm.dev/198)

Check failure on line 73 in src/Currency.php

View workflow job for this annotation

GitHub Actions / Build (8.3)

PropertyTypeCoercion

src/Currency.php:73:23: PropertyTypeCoercion: $this->code expects 'non-empty-string', parent type 'string' provided (see https://psalm.dev/198)
}

/**
* @return array<string, string>
*/
public function serialize(): array
{
return $this->__serialize();
}

// TODO Correct PSALM?
// Correct CODE?
public function unserialize(string $data): void
{
$this->__unserialize((array) $data);

Check failure on line 88 in src/Currency.php

View workflow job for this annotation

GitHub Actions / Build lowest version

UnusedMethodCall

src/Currency.php:88:16: UnusedMethodCall: The call to Money\Currency::__unserialize is not used (see https://psalm.dev/209)

Check failure on line 88 in src/Currency.php

View workflow job for this annotation

GitHub Actions / Psalm

UnusedMethodCall

src/Currency.php:88:16: UnusedMethodCall: The call to Money\Currency::__unserialize is not used (see https://psalm.dev/209)

Check failure on line 88 in src/Currency.php

View workflow job for this annotation

GitHub Actions / Build (8.1)

UnusedMethodCall

src/Currency.php:88:16: UnusedMethodCall: The call to Money\Currency::__unserialize is not used (see https://psalm.dev/209)

Check failure on line 88 in src/Currency.php

View workflow job for this annotation

GitHub Actions / Build (8.2)

UnusedMethodCall

src/Currency.php:88:16: UnusedMethodCall: The call to Money\Currency::__unserialize is not used (see https://psalm.dev/209)

Check failure on line 88 in src/Currency.php

View workflow job for this annotation

GitHub Actions / Build (8.3)

UnusedMethodCall

src/Currency.php:88:16: UnusedMethodCall: The call to Money\Currency::__unserialize is not used (see https://psalm.dev/209)
}
}
Loading