BaselineCommentsCommand::configure()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

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
ccs 2
cts 2
cp 1
crap 1
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 1
    public function __construct(
22
        private CommentsApiInterface $commentsApi
23
    )
24
    {
25 1
        parent::__construct();
26 1
    }
27
28
29 1
    protected function configure(): void
30
    {
31 1
        $this->addArgument('from', InputArgument::OPTIONAL, 'from');
32 1
    }
33
34
    /**
35
     * @param InputInterface $input
36
     * @param OutputInterface $output
37
     * @return int
38
     */
39 1
    protected function execute(InputInterface $input, OutputInterface $output): int
40
    {
41
42 1
        $from = $input->getArgument("from");
43 1
        if ($from != null) {
44
            $this->from = \DateTime::createFromFormat("Y-m-d H:i:s", $from . "00:00:00");
45
        }
46 1
        $this->commentsApi->baseline($this);
47 1
        if ($from != null) {
48
            $output->writeln(sprintf("Successfully base-lined Comments from %s", $from));
49
        } else {
50 1
            $output->writeln(sprintf("Successfully base-lined all Comments"));
51
        }
52
53 1
        return Command::SUCCESS;
54
55
    }
56
57
    /**
58
     * @return \DateTime|null
59
     */
60 1
    public function getFrom(): ?\DateTime
61
    {
62 1
        return $this->from;
63
    }
64
65
66
67
68
}