BaselineCommentsCommand   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Test Coverage

Coverage 88.24%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 15
c 1
b 0
f 0
dl 0
loc 52
ccs 15
cts 17
cp 0.8824
rs 10
wmc 6

4 Methods

Rating   Name   Duplication   Size   Complexity  
A execute() 0 15 3
A configure() 0 3 1
A __construct() 0 5 1
A getFrom() 0 3 1
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
}