SendAbandonedPaymentLink::initialize()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 2
1
<?php
2
3
/*
4
 * This file has been created by developers from BitBag.
5
 * Feel free to contact us once you face any issues or want to start
6
 * You can find more information about us on https://bitbag.io and write us
7
 * an email on [email protected].
8
 */
9
10
declare(strict_types=1);
11
12
namespace BitBag\SyliusMolliePlugin\Cli;
13
14
use BitBag\SyliusMolliePlugin\Creator\AbandonedPaymentLinkCreatorInterface;
15
use Symfony\Component\Console\Command\Command;
16
use Symfony\Component\Console\Input\InputInterface;
17
use Symfony\Component\Console\Output\OutputInterface;
18
use Symfony\Component\Console\Style\SymfonyStyle;
19
use Symfony\Component\Stopwatch\Stopwatch;
20
21
class SendAbandonedPaymentLink extends Command
22
{
23
    public const COMMAND_NAME = 'mollie:send-payment-link';
24
25
    public const COMMAND_ID = 'mollie:send-payment-link';
26
27
    /** @var SymfonyStyle */
28
    private $io;
29
30
    /** @var AbandonedPaymentLinkCreatorInterface */
31
    private $abandonedPaymentLinkCreator;
32
33
    public function __construct(AbandonedPaymentLinkCreatorInterface $abandonedPaymentLinkCreator)
34
    {
35
        parent::__construct(self::COMMAND_NAME);
36
37
        $this->abandonedPaymentLinkCreator = $abandonedPaymentLinkCreator;
38
    }
39
40
    protected function configure(): void
41
    {
42
        $this->setDescription('Send payment link to customers');
43
    }
44
45
    protected function initialize(InputInterface $input, OutputInterface $output): void
46
    {
47
        $this->io = new SymfonyStyle($input, $output);
48
    }
49
50
    protected function execute(InputInterface $input, OutputInterface $output): int
51
    {
52
        $stopwatch = new Stopwatch();
53
        $stopwatch->start(self::COMMAND_ID);
54
55
        $this->io->title('Mollie - send link');
56
57
        try {
58
            $this->io->writeln('Exporting...');
59
            $this->abandonedPaymentLinkCreator->create();
60
61
            $this->io->success('Successfully send all payment links');
62
        } catch (\Exception $exception) {
63
            $this->io->error(\sprintf('An error has occurred during send payment link process. (%s)', $exception->getMessage()));
64
65
            return 1;
66
        }
67
68
        $event = $stopwatch->stop(self::COMMAND_ID);
69
70
        if ($output->isVerbose()) {
71
            $this->io->comment(\sprintf(
72
                'Duration: %.2f ms / Memory: %.2f MB',
73
                $event->getDuration(),
74
                $event->getMemory() / (1024 ** 2)
75
            ));
76
        }
77
78
        return 0;
79
    }
80
}
81