WalletDepositCommand::execute()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 5
nc 1
nop 2
dl 0
loc 10
c 0
b 0
f 0
cc 1
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Damax\ChargeableApi\Bridge\Symfony\Console\Command;
6
7
use Damax\ChargeableApi\Credit;
8
use Symfony\Component\Console\Input\InputArgument;
9
use Symfony\Component\Console\Input\InputInterface;
10
use Symfony\Component\Console\Output\OutputInterface;
11
use Symfony\Component\Console\Style\SymfonyStyle;
12
13
final class WalletDepositCommand extends WalletCommand
14
{
15
    protected static $defaultName = 'damax:chargeable-api:wallet:deposit';
16
17
    protected function configure()
18
    {
19
        $this
20
            ->setDescription('Deposit credit.')
21
            ->addArgument('identity', InputArgument::REQUIRED, 'Identity.')
22
            ->addArgument('credit', InputArgument::REQUIRED, 'Credit.')
23
        ;
24
    }
25
26
    protected function execute(InputInterface $input, OutputInterface $output)
27
    {
28
        $identity = $this->identityFactory->create();
29
30
        $credit = Credit::fromInteger((int) $input->getArgument('credit'));
31
32
        $wallet = $this->walletFactory->create($identity);
33
        $wallet->deposit($credit);
34
35
        (new SymfonyStyle($input, $output))->success(sprintf('Balance: %d', $wallet->balance()->toInteger()));
36
    }
37
}
38