diff --git a/composer.lock b/composer.lock index 7fceeae..375e008 100644 --- a/composer.lock +++ b/composer.lock @@ -2250,16 +2250,16 @@ }, { "name": "squizlabs/php_codesniffer", - "version": "3.9.2", + "version": "3.10.0", "source": { "type": "git", "url": "https://github.com/PHPCSStandards/PHP_CodeSniffer.git", - "reference": "aac1f6f347a5c5ac6bc98ad395007df00990f480" + "reference": "57e09801c2fbae2d257b8b75bebb3deeb7e9deb2" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/PHPCSStandards/PHP_CodeSniffer/zipball/aac1f6f347a5c5ac6bc98ad395007df00990f480", - "reference": "aac1f6f347a5c5ac6bc98ad395007df00990f480", + "url": "https://api.github.com/repos/PHPCSStandards/PHP_CodeSniffer/zipball/57e09801c2fbae2d257b8b75bebb3deeb7e9deb2", + "reference": "57e09801c2fbae2d257b8b75bebb3deeb7e9deb2", "shasum": "" }, "require": { @@ -2326,7 +2326,7 @@ "type": "open_collective" } ], - "time": "2024-04-23T20:25:34+00:00" + "time": "2024-05-20T08:11:32+00:00" }, { "name": "symfony/config", diff --git a/src/TypeMoney.php b/src/TypeMoney.php index 22c48a4..5713695 100644 --- a/src/TypeMoney.php +++ b/src/TypeMoney.php @@ -48,17 +48,11 @@ public function __invoke(): array return [$this->amount, $this->currency]; } - public function toJson(): string + public function toJson(): string|false { return json_encode([ ($this->amount)(), $this->currency->value ]); } - - public static function fromJson(string $data): self - { - [$amount, $currency] = json_decode($data, true); - return self::set($amount, $currency); - } } diff --git a/tests/Unit/TypeMoneyTest.php b/tests/Unit/TypeMoneyTest.php index 041075c..fe03a41 100644 --- a/tests/Unit/TypeMoneyTest.php +++ b/tests/Unit/TypeMoneyTest.php @@ -158,26 +158,4 @@ public static function dataProviderForToJson(): array 'Negative' => [TypeMoney::set(-123.45, 'USD'), '[-123.45,"USD"]'], ]; } - - // --------------------------------------------------------------------------------------------------------------- - - #[Test] - #[DataProvider('dataProviderForFromJson')] - public function checkFromJson(string $data, TypeMoney $expected): void - { - $aux = TypeMoney::fromJson($data); - - self::assertTrue($aux->isEqualTo($expected)); - } - - /** - * @return array> - */ - public static function dataProviderForFromJson(): array - { - return [ - 'Positive' => ['[123.45,"EUR"]', TypeMoney::set(123.45, 'EUR')], - 'Negative' => ['[-123.45,"USD"]', TypeMoney::set(-123.45, 'USD')], - ]; - } }