diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 79b4342cf..c7c207cf0 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -77,7 +77,7 @@ parameters: - message: "#^Cannot call method needs\\(\\) on mixed\\.$#" - count: 4 + count: 6 path: src/WalletServiceProvider.php - diff --git a/src/Internal/Service/LockService.php b/src/Internal/Service/LockService.php index ce5dbf70c..8ef9e9384 100644 --- a/src/Internal/Service/LockService.php +++ b/src/Internal/Service/LockService.php @@ -22,12 +22,11 @@ final class LockService implements LockServiceInterface private CacheRepository $cache; - private int $seconds; - - public function __construct(CacheFactory $cacheFactory) - { + public function __construct( + CacheFactory $cacheFactory, + private int $seconds + ) { $this->cache = $cacheFactory->store(config('wallet.lock.driver', 'array')); - $this->seconds = (int) config('wallet.lock.seconds', 1); $this->lockedKeys = $cacheFactory->store('array'); } diff --git a/src/Internal/Service/MathService.php b/src/Internal/Service/MathService.php index b4476fdd0..df7ab5a1e 100644 --- a/src/Internal/Service/MathService.php +++ b/src/Internal/Service/MathService.php @@ -9,11 +9,9 @@ final class MathService implements MathServiceInterface { - private int $scale; - - public function __construct() - { - $this->scale = (int) config('wallet.math.scale', 64); + public function __construct( + private int $scale + ) { } public function add(float|int|string $first, float|int|string $second, ?int $scale = null): string diff --git a/src/WalletServiceProvider.php b/src/WalletServiceProvider.php index 8b99c2820..60b97952a 100644 --- a/src/WalletServiceProvider.php +++ b/src/WalletServiceProvider.php @@ -216,7 +216,17 @@ private function internal(array $configure): void $this->app->singleton(DatabaseServiceInterface::class, $configure['database'] ?? DatabaseService::class); $this->app->singleton(DispatcherServiceInterface::class, $configure['dispatcher'] ?? DispatcherService::class); $this->app->singleton(JsonServiceInterface::class, $configure['json'] ?? JsonService::class); + + $this->app->when($configure['lock'] ?? LockService::class) + ->needs('$seconds') + ->giveConfig('wallet.lock.seconds', 1); + $this->app->singleton(LockServiceInterface::class, $configure['lock'] ?? LockService::class); + + $this->app->when($configure['math'] ?? MathService::class) + ->needs('$scale') + ->giveConfig('wallet.math.scale', 64); + $this->app->singleton(MathServiceInterface::class, $configure['math'] ?? MathService::class); $this->app->singleton(StateServiceInterface::class, $configure['state'] ?? StateService::class); $this->app->singleton(TranslatorServiceInterface::class, $configure['translator'] ?? TranslatorService::class);