Test Setup Failed
Push — main ( abdcb9...2e5f68 )
by Slawomir
04:37
created

BaselineCommentsCommand::getFrom()   A

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
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
3
namespace App\Modules\Comments\Api\Command;
4
5
use App\Modules\Comments\Api\CommentsApiInterface;
6
use Symfony\Component\Console\Command\Command;
7
use Symfony\Component\Console\Input\InputArgument;
8
use Symfony\Component\Console\Input\InputInterface;
9
use Symfony\Component\Console\Output\OutputInterface;
10
11
class BaselineCommentsCommand extends Command
12
{
13
14
    protected static $defaultName = 'app:comments:baseline';
15
16
    private ?\DateTime $from = null;
17
18
    /**
19
     * @param CommentsApiInterface $commentsApi
20
     */
21
    public function __construct(
22
        private CommentsApiInterface $commentsApi
23
    )
24
    {
25
        parent::__construct();
26
    }
27
28
29
    protected function configure(): void
30
    {
31
        $this->addArgument('from', InputArgument::OPTIONAL, 'from');
32
    }
33
34
    /**
35
     * @param InputInterface $input
36
     * @param OutputInterface $output
37
     * @return int
38
     */
39
    protected function execute(InputInterface $input, OutputInterface $output): int
40
    {
41
42
        $from = $input->getArgument("from");
43
        if ($from != null) {
44
            $this->from = \DateTime::createFromFormat("Y-m-d H:i:s", $from . "00:00:00");
45
        }
46
        $this->commentsApi->baseline($this);
47
        if ($from != null) {
48
            $output->writeln(sprintf("Successfully base-lined Comments from %s", $from));
49
        } else {
50
            $output->writeln(sprintf("Successfully base-lined all Comments"));
51
        }
52
53
        return Command::SUCCESS;
54
55
    }
56
57
    /**
58
     * @return \DateTime|null
59
     */
60
    public function getFrom(): ?\DateTime
61
    {
62
        return $this->from;
63
    }
64
65
66
67
68
}