Skip to content

Commit

Permalink
feat: allow un/serialize for currency
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris8934 committed Jan 26, 2024
1 parent 51b70fe commit 18993f4
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 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 @@ -66,8 +67,23 @@ 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?
public function unserialize(string $data)

Check failure on line 85 in src/Currency.php

View workflow job for this annotation

GitHub Actions / Build lowest version

MethodSignatureMustProvideReturnType

src/Currency.php:85:21: MethodSignatureMustProvideReturnType: Method Money\Currency::unserialize must have a return type signature (see https://psalm.dev/282)

Check failure on line 85 in src/Currency.php

View workflow job for this annotation

GitHub Actions / Psalm

MethodSignatureMustProvideReturnType

src/Currency.php:85:21: MethodSignatureMustProvideReturnType: Method Money\Currency::unserialize must have a return type signature (see https://psalm.dev/282)

Check failure on line 85 in src/Currency.php

View workflow job for this annotation

GitHub Actions / Build (8.1)

MethodSignatureMustProvideReturnType

src/Currency.php:85:21: MethodSignatureMustProvideReturnType: Method Money\Currency::unserialize must have a return type signature (see https://psalm.dev/282)

Check failure on line 85 in src/Currency.php

View workflow job for this annotation

GitHub Actions / Build (8.2)

MethodSignatureMustProvideReturnType

src/Currency.php:85:21: MethodSignatureMustProvideReturnType: Method Money\Currency::unserialize must have a return type signature (see https://psalm.dev/282)

Check failure on line 85 in src/Currency.php

View workflow job for this annotation

GitHub Actions / Build (8.3)

MethodSignatureMustProvideReturnType

src/Currency.php:85:21: MethodSignatureMustProvideReturnType: Method Money\Currency::unserialize must have a return type signature (see https://psalm.dev/282)
{
return $this->__unserialize($data);

Check failure on line 87 in src/Currency.php

View workflow job for this annotation

GitHub Actions / Build lowest version

InvalidReturnStatement

src/Currency.php:87:16: InvalidReturnStatement: No return values are expected for Money\Currency::unserialize (see https://psalm.dev/128)

Check failure on line 87 in src/Currency.php

View workflow job for this annotation

GitHub Actions / Build lowest version

InvalidArgument

src/Currency.php:87:37: InvalidArgument: Argument 1 of Money\Currency::__unserialize expects array<array-key, mixed>, but string provided (see https://psalm.dev/004)

Check failure on line 87 in src/Currency.php

View workflow job for this annotation

GitHub Actions / Psalm

InvalidReturnStatement

src/Currency.php:87:16: InvalidReturnStatement: No return values are expected for Money\Currency::unserialize (see https://psalm.dev/128)

Check failure on line 87 in src/Currency.php

View workflow job for this annotation

GitHub Actions / Psalm

InvalidArgument

src/Currency.php:87:37: InvalidArgument: Argument 1 of Money\Currency::__unserialize expects array<array-key, mixed>, but string provided (see https://psalm.dev/004)

Check failure on line 87 in src/Currency.php

View workflow job for this annotation

GitHub Actions / Build (8.1)

InvalidReturnStatement

src/Currency.php:87:16: InvalidReturnStatement: No return values are expected for Money\Currency::unserialize (see https://psalm.dev/128)

Check failure on line 87 in src/Currency.php

View workflow job for this annotation

GitHub Actions / Build (8.1)

InvalidArgument

src/Currency.php:87:37: InvalidArgument: Argument 1 of Money\Currency::__unserialize expects array<array-key, mixed>, but string provided (see https://psalm.dev/004)

Check failure on line 87 in src/Currency.php

View workflow job for this annotation

GitHub Actions / Build (8.2)

InvalidReturnStatement

src/Currency.php:87:16: InvalidReturnStatement: No return values are expected for Money\Currency::unserialize (see https://psalm.dev/128)

Check failure on line 87 in src/Currency.php

View workflow job for this annotation

GitHub Actions / Build (8.2)

InvalidArgument

src/Currency.php:87:37: InvalidArgument: Argument 1 of Money\Currency::__unserialize expects array<array-key, mixed>, but string provided (see https://psalm.dev/004)

Check failure on line 87 in src/Currency.php

View workflow job for this annotation

GitHub Actions / Build (8.3)

InvalidReturnStatement

src/Currency.php:87:16: InvalidReturnStatement: No return values are expected for Money\Currency::unserialize (see https://psalm.dev/128)

Check failure on line 87 in src/Currency.php

View workflow job for this annotation

GitHub Actions / Build (8.3)

InvalidArgument

src/Currency.php:87:37: InvalidArgument: Argument 1 of Money\Currency::__unserialize expects array<array-key, mixed>, but string provided (see https://psalm.dev/004)
}
}

0 comments on commit 18993f4

Please sign in to comment.