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

[11.x] New Version #826

Merged
merged 32 commits into from
Jan 23, 2024
Merged
Changes from 2 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
1a29e92
working on a new version
rez1dent3 Dec 30, 2023
18eb7dc
phpstan fix
rez1dent3 Dec 30, 2023
83e3de5
ecs fix
rez1dent3 Dec 30, 2023
e7d64c9
add native soft delete
rez1dent3 Dec 30, 2023
bf9148b
Merge pull request #827 from bavix/11.x-soft-delete
rez1dent3 Dec 30, 2023
93437ad
fix default wallet
rez1dent3 Dec 30, 2023
e22269e
Merge pull request #828 from bavix/11.x-soft-delete
rez1dent3 Dec 30, 2023
6f06d2f
update baseline
rez1dent3 Dec 30, 2023
ce948f2
add namespace
rez1dent3 Dec 30, 2023
b2d1fc5
minimum php version changed
rez1dent3 Dec 30, 2023
486b26e
revert namespace
rez1dent3 Dec 31, 2023
3b2d146
add units
rez1dent3 Dec 31, 2023
15e7ee1
update composer.json
rez1dent3 Dec 31, 2023
873bbc2
add FormatterServiceInterface
rez1dent3 Dec 31, 2023
437c21a
Merge pull request #834 from bavix/11.x-831-the-buy-function-only-acc…
rez1dent3 Jan 5, 2024
9d2fdc2
add FormatterServiceInterface
rez1dent3 Jan 5, 2024
7c7d693
Merge pull request #835 from bavix/11.x-831-the-buy-function-only-acc…
rez1dent3 Jan 5, 2024
d8c2ad8
rector fix
rez1dent3 Jan 5, 2024
5e2e9ff
Merge pull request #836 from bavix/11.x-831-the-buy-function-only-acc…
rez1dent3 Jan 5, 2024
5f41417
Merge branch 'master' into 11.x
rez1dent3 Jan 5, 2024
1d4a652
fix Qodana
rez1dent3 Jan 5, 2024
8b760f0
Merge pull request #837 from bavix/11.x-831-the-buy-function-only-acc…
rez1dent3 Jan 5, 2024
f956ed0
technical debt
rez1dent3 Jan 5, 2024
48f82c9
add gmp-ext
rez1dent3 Jan 5, 2024
5f31479
Revert "add gmp-ext"
rez1dent3 Jan 5, 2024
9579ffd
dto fix
rez1dent3 Jan 5, 2024
a04c760
Merge pull request #838 from bavix/11.x-dto-refactoring
rez1dent3 Jan 5, 2024
826eca9
drop depends
rez1dent3 Jan 5, 2024
d2fe9bd
remove cknow/laravel-money
rez1dent3 Jan 5, 2024
04486ef
Merge pull request #839 from bavix/11.x-remove-depends-cknow
rez1dent3 Jan 5, 2024
af18d66
Merge branch 'master' into 11.x
rez1dent3 Jan 6, 2024
ec4b994
merge origin/master
rez1dent3 Jan 20, 2024
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
24 changes: 24 additions & 0 deletions src/Services/FormatterService.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

declare(strict_types=1);

namespace Bavix\Wallet\Services;

use Brick\Math\BigDecimal;
use Brick\Math\RoundingMode;

final readonly class FormatterService implements FormatterServiceInterface
{
public function intValue(string|int|float $amount, int $decimalPlaces): string
{
return (string) BigDecimal::ten()
->power($decimalPlaces)
->multipliedBy(BigDecimal::of($amount))
->toScale(0, RoundingMode::DOWN);
}

public function floatValue(string|int|float $amount, int $decimalPlaces): string
{
return (string) BigDecimal::ofUnscaledValue($amount, $decimalPlaces);
}
}
15 changes: 15 additions & 0 deletions src/Services/FormatterServiceInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

declare(strict_types=1);

namespace Bavix\Wallet\Services;

/**
* @internal
*/
interface FormatterServiceInterface
{
public function intValue(string|int|float $amount, int $decimalPlaces): string;

public function floatValue(string|int|float $amount, int $decimalPlaces): string;
}
55 changes: 55 additions & 0 deletions tests/Units/Service/FormatterTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php

declare(strict_types=1);

namespace Bavix\Wallet\Test\Units\Service;

use Bavix\Wallet\Internal\Exceptions\ExceptionInterface;
use Bavix\Wallet\Services\FormatterServiceInterface;
use Bavix\Wallet\Test\Infra\TestCase;

/**
* @internal
*/
final class FormatterTest extends TestCase
{
/**
* @throws ExceptionInterface
*/
public function testFloatValueDP3(): void
{
$result = app(FormatterServiceInterface::class)->floatValue('12345', 3);

self::assertSame('12.345', $result);
}

/**
* @throws ExceptionInterface
*/
public function testFloatValueDP2(): void
{
$result = app(FormatterServiceInterface::class)->floatValue('12345', 2);

self::assertSame('123.45', $result);
}

/**
* @throws ExceptionInterface
*/
public function testIntValueDP3(): void
{
$result = app(FormatterServiceInterface::class)->intValue('12.345', 3);

self::assertSame('12345', $result);
}

/**
* @throws ExceptionInterface
*/
public function testIntValueDP2(): void
{
$result = app(FormatterServiceInterface::class)->intValue('123.45', 2);

self::assertSame('12345', $result);
}
}